Problem With Repeat
#1
Posted 11 February 2006 - 08:37 PM
But I have a problem .
Is it possible to use a 'repeat loop' in another 'repeat loop'?
(like 'Will loops' in Basic)
For example my game run very well but I want
the program return at top when you lost!
I tried to make a big loop with every other.
"
repeat
repeat
...
until ...
repeat
...
until ...
repeat
...
until ...
until ...
"
But it didn't work!
#2
Posted 11 February 2006 - 08:56 PM
Try to avoid "Basic-like" programming: use functions to cut your program into smaller and more readable parts. This way your program's structure will get clearer, and there are high chances that it will work normally after you rewrote it correctly
#3
Posted 11 February 2006 - 09:00 PM
while 1 do --main menu while 1 do --the game if ... then break end end end
It should work... But a 'goto' command should sometimes be useful, although I rarely use it in my "old basic programs".
#4
Posted 11 February 2006 - 09:14 PM
function showmenu() ... if(user wants to play) then return 1 end if(user wants to quit) then return 2 end if(user wants to see credits) then return 3 end ... end function playgame() repeat ... until ... end function showcredits() ... end repeat choice = showmenu() if(choice==1) then playgame() else if(choice==3) then showcredits() end until choice==2
#5
Posted 12 February 2006 - 10:08 AM
Can I put my b?ta in the CAPS Website?
All => I had ever cut the program a little.
I will try again to use another repeat!
Can you give me the 'while' syntax in lua?
#6
Posted 12 February 2006 - 10:18 AM
repeat should work fine. Just check your code to find out what's happening (and if you can't read it easily because it is too big, cut it in even smaller parts).I will try again to use another repeat!
Can you give me the 'while' syntax in lua?
while ... do ... end
#7
Posted 12 February 2006 - 11:06 AM
Thanks
I will post it in the CAPS at home (in 3 days).
It is not really a game but a program where you make everything with pen.
Another question:
Is the getkey() function slower than the getpen() function?
(another of my program use the keyboard and is very slow!)
#8
Posted 12 February 2006 - 11:35 AM
#9
Posted 12 February 2006 - 11:42 AM
How can I use the testkey() function?
Thank's
#10
Posted 12 February 2006 - 11:57 AM
#11
Posted 12 February 2006 - 01:15 PM
K_0 ... K_9
K_EXE
K_PLUS
K_MINUS
K_LEFT, K_RIGHT, K_UP, K_DOWN
Backspace Code (<-) = 8 (I don't know if a K_ define exists)
There are all the codes I know, maybe there are more
#12
Posted 12 February 2006 - 05:09 PM
I will test testkey()
#13
Posted 12 February 2006 - 05:20 PM
The following names can be used as key codes:
K_BACK,
K_UP, K_DOWN, K_LEFT, K_RIGHT
K_0, K_1, K_2, ..., K_9
K_EQUAL, K_x, K_y, K_z, K_POWER, K_DIV
K_LPAR, K_RPAR, K_COMMA, K_TIMES, K_MINUS, K_PLUS, K_DOT, K_EXP, K_EXE
I know that there is no good documentation for CPLua, but you can't say that there is nothing
#14
Posted 12 February 2006 - 05:58 PM
holidays!
#15
Posted 12 February 2006 - 10:33 PM
If testkey(k_8) == true then
...
end
It doesn't work!
Yes!
I wrote k_ for K_
#16
Posted 13 February 2006 - 12:38 PM
#17
Posted 13 February 2006 - 03:31 PM
if testkey(K_8) == true then ... endis ok
#18
Posted 14 February 2006 - 10:01 AM
if testkey(K_8) then ... endWork too!
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users