Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Mutiple loops running
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
caldrium




PostPosted: Wed Jan 18, 2006 4:05 pm   Post subject: Mutiple loops running

i am making a game for school and i dunno how to make multiple loops run at once, or if you can...


i am runnign 2 loops that need to be done right now

var fish, fishy, level, size : int
var buttons : array char of boolean
var maxX, maxY : int := 200
level := 1

procedure fishSpawn
loop
randint (fish, level, 50)
if (fish = 50) then
randint (fishy, 50, maxy)
randint (size, 10, 30)
Draw.FillOval (maxx, fishy, size, size, 2)
delay (2000)
end if
end loop
end fishSpawn

%fishSpawn
loop
View.Update
Draw.FillOval (maxX, maxY, 20, 20, 5)
Input.KeyDown (buttons)
if buttons (KEY_UP_ARROW) then
maxY := maxY + 2
elsif buttons (KEY_DOWN_ARROW) then
maxY := maxY - 2
elsif buttons (KEY_LEFT_ARROW) then
maxX := maxX - 2
elsif buttons (KEY_RIGHT_ARROW) then
maxX := maxX + 2
end if
colorback (100)
delay (20)
cls
end loop

i have %'d the fishSpawn cause both cant run at once..
how would i be able to still move AND have the fish spawn at the same time?
your help would be greatly appreciated.(btw there circles for now until i make the fishes lol)
Sponsor
Sponsor
Sponsor
sponsor
Albrecd




PostPosted: Wed Jan 18, 2006 5:15 pm   Post subject: (No subject)

You could put one of the loops in a (squeemish look away) process (they can be useful if you use them correctly [against popular belief]).

All you have to do is declare a process with one of the loops in it and fork it right before the other loop.
Cervantes




PostPosted: Wed Jan 18, 2006 5:31 pm   Post subject: (No subject)

Albrecd wrote:
You could put one of the loops in a (squeemish look away) process (they can be useful if you use them correctly [against popular belief]).


Popular belief is that processes will not be used well by those who are first learning them. Tony's tutorials clearly showed how processes can be calmed. Processes can be good, but for the overwhelming majority of we get about them, they are not the way to go. Questions like this one.


caldrium: you don't need your fishSpawn procedure in a separate loop. Put it in the same loop, and things should work fine.

code:

loop  % This is your main loop, and you only need it.
  if Rand.Int (1, 50) = 1 then  % Functions > Procedures
    % spawn_a_fish
  end if
  % Game controls
  % Drawing
end loop
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: