Author Topic: Balance game  (Read 7100 times)

0 Members and 1 Guest are viewing this topic.

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Balance game
« Reply #15 on: November 15, 2011, 02:10:13 pm »
Do you mean convert a table to a string, or opposite?
To simple display a table number value, use this:
Code: [Select]
a={1,2,3}
nr=1
text=tostring(a[nr])

Edit:
I get it.
If the table is a global table, you can do this
Code: [Select]
ball1={1,2,3}
nr=1

thetable = _G["ball" .. nr][5]

_G is the global table.
« Last Edit: November 15, 2011, 02:15:09 pm by jimbauwens »

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Balance game
« Reply #16 on: November 15, 2011, 02:14:18 pm »
Instead of having to mess aroud with dynnamic variable names, I'd have put new balls in a Balls table, then assign an id to a ball, and call it by reading/writing like that :

Balls[ballID][1]

I did that kind of thing for my BreakOut game :

Code: [Select]
    aBall = Ball(math.random(10,platform.window:width()-10-XLimit),platform.window:height()-26,-1-speedDiff,-1-speedDiff,#BallsTable+1)
    table.insert(BallsTable,aBall)

Full source here.
« Last Edit: November 15, 2011, 02:14:53 pm by adriweb »
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Balance game
« Reply #17 on: November 15, 2011, 02:18:18 pm »
Yes, its better to keep a table with your balls in it, more flexible that way :)
* jimbauwens smacks himself

Offline Nick

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1166
  • Rating: +161/-3
  • You just got omnom'd
    • View Profile
    • Nick Steen
Re: Balance game
« Reply #18 on: November 15, 2011, 02:23:12 pm »
thanks both, but i'll use adriweb's way, it'll be easier xp

well in fact, that's the way i did it with tetris too, but with blocks, but i seem to have forgotten that xp
« Last Edit: November 15, 2011, 02:27:59 pm by Nick »

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Balance game
« Reply #19 on: November 15, 2011, 02:25:16 pm »
And better :)