Jump to content



Photo

Problem With Repeat


  • Please log in to reply
17 replies to this topic

#1 numerix

numerix

    Newbie

  • Members
  • Pip
  • 18 posts
  • Location:France

  • Calculators:
    graph 65
    classpad 300

Posted 11 February 2006 - 08:37 PM

:D I wrote my first game in CPlua!

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 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 11 February 2006 - 08:56 PM

It should work :huh:

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 Kilburn

Kilburn

    Casio Technician

  • Members
  • PipPipPipPipPipPip
  • 491 posts
  • Gender:Male
  • Location:France
  • Interests:Blah

  • Calculators:
    FX-7500 G
    ClassPad 300

Posted 11 February 2006 - 09:00 PM

I often use 'while 1 do ~ end' loops in my programs, like

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". :lol:

#4 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

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 numerix

numerix

    Newbie

  • Members
  • Pip
  • 18 posts
  • Location:France

  • Calculators:
    graph 65
    classpad 300

Posted 12 February 2006 - 10:08 AM

Kilburn => In basic I used 'While 1=1' ! :lol:
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? :huh:

#6 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 12 February 2006 - 10:18 AM

I will try again to use another repeat!

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).

Can you give me the 'while' syntax in lua? :huh:

while ... do
...
end
;)

#7 numerix

numerix

    Newbie

  • Members
  • Pip
  • 18 posts
  • Location:France

  • Calculators:
    graph 65
    classpad 300

Posted 12 February 2006 - 11:06 AM

No problem it work now! :)
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!) :unsure:

#8 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 12 February 2006 - 11:35 AM

The speed is the same, but testkey() should give better results than getkey(). You should use it when speed is important :)

#9 numerix

numerix

    Newbie

  • Members
  • Pip
  • 18 posts
  • Location:France

  • Calculators:
    graph 65
    classpad 300

Posted 12 February 2006 - 11:42 AM

Yes here the speed is inportant :D
How can I use the testkey() function? :)
Thank's

#10 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 12 February 2006 - 11:57 AM

testkey() can be used to check the state of a particular key; for example testkey(K_EXE) returns true if the key <span class=EXE' /> is currently pressed.

#11 Kilburn

Kilburn

    Casio Technician

  • Members
  • PipPipPipPipPipPip
  • 491 posts
  • Gender:Male
  • Location:France
  • Interests:Blah

  • Calculators:
    FX-7500 G
    ClassPad 300

Posted 12 February 2006 - 01:15 PM

You can use these following codes:
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 :unsure:

#12 numerix

numerix

    Newbie

  • Members
  • Pip
  • 18 posts
  • Location:France

  • Calculators:
    graph 65
    classpad 300

Posted 12 February 2006 - 05:09 PM

:D Super!
I will test testkey() :lol2:

#13 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 12 February 2006 - 05:20 PM

Extract of the file functions.txt:

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 numerix

numerix

    Newbie

  • Members
  • Pip
  • 18 posts
  • Location:France

  • Calculators:
    graph 65
    classpad 300

Posted 12 February 2006 - 05:58 PM

Yes I know there is some documentation but I am not in my habitual mac during
holidays! :)

#15 numerix

numerix

    Newbie

  • Members
  • Pip
  • 18 posts
  • Location:France

  • Calculators:
    graph 65
    classpad 300

Posted 12 February 2006 - 10:33 PM

I wrote:

If testkey(k_8) == true then
...
end


It doesn't work!

Yes!
I wrote k_ for K_ :roflol:

#16 MicroPro

MicroPro

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 640 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    Casio ClassPad 300

Posted 13 February 2006 - 12:38 PM

You must either write "if testkey(8)==true" or "if testkey(K_BACK)==true".

#17 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 13 February 2006 - 03:31 PM

if testkey(K_8) == true then ... end
is ok ;)

#18 numerix

numerix

    Newbie

  • Members
  • Pip
  • 18 posts
  • Location:France

  • Calculators:
    graph 65
    classpad 300

Posted 14 February 2006 - 10:01 AM

if testkey(K_8) then 
... 
end
Work too!
:)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users