1

Topic: [LUA] question

Hello.
I am trying to learn LUA because of 0.6.0 release, but i have a problem.
I can create an array (if it is not array, say me the right name) with:

players={name="Khubajsn","Khubajsn2", score="10","20"}

And now, I want to get score of Khubajsn2 (its 20). Is it possible? Or I must create an table? If I must, how? And how i can get the value of that table?
I am sorry, but i dont understand Lua manual a lot sad
Thanks,
Khubajsn

Goodbye all. Account inactive since March 2011.

2

Re: [LUA] question

http://lua-users.org/wiki/TutorialDirectory
http://www.devmaster.net/wiki/Lua_(Tutorial)

.. just search google... xDD

Remember me? Questions? Just leave a message, I will respond within 72 hrs!

3

Re: [LUA] question

Nice links but there isnt a lua program for windows on there sad

Bye.

4

Re: [LUA] question

http://lua-users.org/wiki/LuaBinaries
http://www.gorlice.net.pl/~rybak/luaide/


ok? -> http://justfuckinggoogleit.com/search.p … ua+windows

Remember me? Questions? Just leave a message, I will respond within 72 hrs!

5 (edited by Pocram 2009-04-01 20:05:26)

Re: [LUA] question

I would clean it up a bit, so you see what variable belongs to wich player.

players = {}
    players[1] = {}
        players[1].name = "Khubajsn"
        players[1].score = 10
    players[2] = {}
        players[2].name = "Khubajsn2"
        players[2].score = 20
    players[3] = {}
        players[3].name = "Khubajsn3"
        players[3].score = 30
-- With a loop
print ("Player "..players[1].name.." has got "..players[1].score.." points.")
print ("Player "..players[2].name.." has got "..players[2].score.." points.")
print ("Player "..players[3].name.." has got "..players[3].score.." points.")
print ("")
-- Without a loop
   -- This loop gets the number of players. (3 in this case)
for i, v in pairs(players) do
    x = i -- Saves the number :D
end
for i = 1,x,1 do -- Starts the loop to tell us every player with it's points.
    print ("Player "..players[i].name.." has got "..players[i].score.." points.") -- Oh, .. means.. "Print this in the same line" ;)
end

Try this one big_smile

» Use the Search-Function before asking questions!

6 (edited by DinoSmoothie 2009-04-01 19:49:02)

Re: [LUA] question

Thx and sry, just a quick post, will you start modding for the wii version yet? once you've played the engine of course.

Bye.

7

Re: [LUA] question

haha .. i just googled for the wiieingine and found the file posted in the other topic big_smile

Remember me? Questions? Just leave a message, I will respond within 72 hrs!

8

Re: [LUA] question

Pocram wrote:

I would clean it up a bit, so you see what variable belongs to wich player.

players = {}
    players[1] = {}
        players[1].name = "Khubajsn"
        players[1].score = 10
    players[2] = {}
        players[2].name = "Khubajsn2"
        players[2].score = 20
    players[3] = {}
        players[3].name = "Khubajsn3"
        players[3].score = 30
-- With a loop
print ("Player "..players[1].name.." has got "..players[1].score.." points.")
print ("Player "..players[2].name.." has got "..players[2].score.." points.")
print ("Player "..players[3].name.." has got "..players[3].score.." points.")
print ("")
-- Without a loop
   -- This loop gets the number of players. (3 in this case)
for i, v in pairs(players) do
    x = i -- Saves the number :D
end
for i = 1,x,1 do -- Starts the loop to tell us every player with it's points.
    print ("Player "..players[i].name.." has got "..players[i].score.." points.") -- Oh, .. means.. "Print this in the same line" ;)
end

Try this one big_smile

The loop is too complicated. It's easier this way:

for nr, player in pairs(players) do
print (nr .. ". " ..  "Player " .. player.name .. " has got " .. player.score .. " points.") 
end

--output:
1. Player Khubajsn has got 10 points.
2. Player Khubajsn2 has got 20 points.
3. Player Khubajsn3 has got 30 points.


--the number of elements in a table:
print (# players)
--output:
3
aka cheesy

9

Re: [LUA] question

Thank you all for the fast replies!
All codes you give me here works.
Very big thanks to Pocram - you explain it to me.
Very big thanks also to grummi - you show me the shorter code.
If i will have other questions, i will send them here smile
Thank you all a lot!

Goodbye all. Account inactive since March 2011.

10

Re: [LUA] question

@khubajsn how lua going man , you writen any killer scripts yet?

11

Re: [LUA] question

DiM SuM! wrote:

@khubajsn how lua going man , you writen any killer scripts yet?

Hmm...
Some scripts yes, but killer scripts no yet smile

Goodbye all. Account inactive since March 2011.

12

Re: [LUA] question

khubajsn wrote:
DiM SuM! wrote:

@khubajsn how lua going man , you writen any killer scripts yet?

Hmm...
Some scripts yes, but killer scripts no yet smile

kool man  wat have u writen? can i have a butchers?

13

Re: [LUA] question

Finished scripts:
- Is it same word??
- How much is A : B
- CPU time
- Printing numbers from 1 to 10 000 (with for cycle)
- Arrays

Goodbye all. Account inactive since March 2011.

14 (edited by Pocram 2009-04-05 17:33:33)

Re: [LUA] question

khubajsn wrote:

- Is it same word??

Do you mean

worda = "lol"
wordb = "omg"

Or do you figured out how to insert user inputes while the script is running?

Anyways, try to make a script like my Teeworlds Fightcalc. You can see it in the "Other" section.

- Pocram

» Use the Search-Function before asking questions!

15

Re: [LUA] question

No, I dont Pocram.
There is a function:

 function issame(a,b)
  if (a == b) then
   print("Yes, them are same");
  else
   print("No, them arent same");
  end
 end

and you call:
issame("lol","omg")
----
Your FightCalc is not bad, but its simple. You just declare arrays with players info and then you work with them smile
If i try to make script like it, i will make it more time thn you because im novice in Lua programing, but i will finish it ;-)
P.S.: Just wait ... O,...,O

Goodbye all. Account inactive since March 2011.