English Lua: Not cs2d lua.

15 replies
Goto Page
To the start Previous 1 Next To the start
25.01.12 01:14:50 pm
Up
Glix
User
Offline Off
Guys i want to know did i all ok?
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
function fibo()
  a, b = 0, 1
  while true do
    coroutine.yield(a)
    a, b = b, a + b
  end
end

co = coroutine.create(fibo)

for i = 1, 20 do
  print(coroutine.resume(co))
end


and i got for that this

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
edited 1×, last 25.01.12 05:44:14 pm
Create free website for your clan! Create server control panel webE --->http://www.000webhost.com/581961.html
25.01.12 01:21:00 pm
Up
Alistaire
User
Offline Off
So where did you put the i from;

Code:
1
2
3
for i=1,20 do
     print(coroutine.resume(co))
end


?
IMG:http://i.imgur.com/5zhwOTP.png
25.01.12 02:13:39 pm
Up
DannyDeth
User
Offline Off
Your function was done perfectly.
25.01.12 03:20:01 pm
Up
Glix
User
Offline Off
@user DannyDeth: thx for info, but what wrong is with this?. ( I'm learning lua)

Code:
1
2
3
io.write("Enter your name: ")
name = io.read()
print("Hello, ".. name);
Create free website for your clan! Create server control panel webE --->http://www.000webhost.com/581961.html
25.01.12 03:38:16 pm
Up
Alistaire
User
Offline Off
That's for something else in Lua. CS2D doesn't use it (yet).
IMG:http://i.imgur.com/5zhwOTP.png
25.01.12 03:49:48 pm
Up
Glix
User
Offline Off
Guys what wrong with this please answer fastly... I nee your help
Code:
1
io.write("Enter your age man: "); age = io.read(); print("You are " .. age .. "Old!")
edited 4×, last 25.01.12 04:54:33 pm
Create free website for your clan! Create server control panel webE --->http://www.000webhost.com/581961.html
25.01.12 04:59:44 pm
Up
Banaan
User
Offline Off
CS2D doesn't send any data to stdin (which you are trying to receive using io.read()). Where should the data be coming from? From the console? In that case you should use the cs2d lua hook parse hook to retrieve any entered data.

So for this to work, you should run it through the standard Lua interpreter you installed (lua.exe).
25.01.12 05:07:03 pm
Up
Glix
User
Offline Off
Guys this is not from cs2d lua it from normal lua. I am learning it and need your help.
Create free website for your clan! Create server control panel webE --->http://www.000webhost.com/581961.html
25.01.12 05:11:54 pm
Up
Kel9290
User
Offline Off
Code:
1
2
3
4
io.write("Print your name:")
-- you are printing it here
name = io.read()
print("Hello, "..name)
under the stone.
25.01.12 05:24:01 pm
Up
Glix
User
Offline Off
Thanx kel.. can you help me with this?
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
io.write("Enter a message: ")
userinput = io.read()

if userinput == "hi" then
     print("Well howdy there!")
elseif userinput == "bye" then
     print("Goodbye!")
elseif userinput == "hello" then
     print("Hi")
elseif userinput == "Hu" then
     print("Spelling error much?")
else
     print("I don't understand you. Sorry.")
end
Create free website for your clan! Create server control panel webE --->http://www.000webhost.com/581961.html
25.01.12 05:49:08 pm
Up
Kel9290
User
Offline Off
just create new .txt file, copy your script in this file, then rename it to <anynamehere>.lua. Select your .lua and drag & drop on lua.exe.

also, put io.read() at end if you don't want window close after writing a text.
under the stone.
25.01.12 05:52:02 pm
Up
Glix
User
Offline Off
where do i put io.read()? after
Code:
1
end
or? before
Create free website for your clan! Create server control panel webE --->http://www.000webhost.com/581961.html
25.01.12 06:10:25 pm
Up
Kel9290
User
Offline Off
after.
under the stone.
25.01.12 06:23:19 pm
Up
Glix
User
Offline Off
[command]io.write("Enter a message: ")
userinput = io.read()

if userinput == "hi" then
print("Well howdy there!")
elseif userinput == "bye" then
print("Goodbye!")
elseif userinput == "hello" then
print("Hi")
elseif userinput == "Hu" then
print("Spelling error much?")
else
print("I don't understand you. Sorry.")
end[/command]

How i can make that like when you say hi. It prints tho print("Well howdy there!") then it returns again says enter msg.
Create free website for your clan! Create server control panel webE --->http://www.000webhost.com/581961.html
25.01.12 08:34:22 pm
Up
Alistaire
User
Offline Off
Your script reminds me of my tries to make a .vb script.

Good times. Posting it in the startup shit of my school's computer. From my friends account.

Good times.
IMG:http://i.imgur.com/5zhwOTP.png
25.01.12 10:53:31 pm
Up
Banaan
User
Offline Off
Put it in a never-ending while loop:

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
while true do
     io.write("Enter a message: ")
     userinput = io.read()

     if userinput == "hi" then
          print("Well howdy there!")
     elseif userinput == "bye" then
          print("Goodbye!")
     elseif userinput == "hello" then
          print("Hi")
     elseif userinput == "Hu" then
          print("Spelling error much?")
     else
          print("I don't understand you. Sorry.")
     end
end


After printing a reply to the user input, this will return to the start where you enter a message.
To the start Previous 1 Next To the start