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

Username:   Password: 
 RegisterRegister   
 Running and stopping a particle script, without ending the whole program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
montesser




PostPosted: Fri Nov 12, 2010 11:07 am   Post subject: Running and stopping a particle script, without ending the whole program

What is it you are trying to achieve?
To have my program run my snow particle / space scene, with a designated amount of time and then allow the rest of the program to continue,


What is the problem you are having?
I can make the particles start, but cannot stop them.


Describe what you have tried to solve this problem
i have tried delays, exit whens, and even exit when count.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


View.Set ("offscreenonly")
colorback (black)
const MaxParticles := 500
const startfirex := 100
const startfirey := 100
const smokelength := 300

type Particle_Type : %declare type
record
x, y, speed : real
end record

var Particles : array 1 .. MaxParticles of Particle_Type %declare array of type that you've made


for i : 1 .. MaxParticles % give particles their initial x,y value
Particles (i).x := Rand.Int (0, maxx) %randmize the x position
Particles (i).y := Rand.Int (0, maxy) %randmize the y position
Particles (i).speed := Rand.Int (3, 5) %randmize the y position


end for


loop %main animation loop
cls %clear the screen

for i : 1 .. MaxParticles %inside this loop we go through all the particles 1 by 1
Particles (i).y -= Particles (i).speed %move down the drop of rain

if Particles (i).y <= 0 then %if drop of rain has fallen to the ground, reset it's values
Particles (i).y := maxy %set it's y location back to the top again
Particles (i).x := Rand.Int (0, maxx) %randmize the x position of rain droplets from 0 to maxx
Particles (i).speed := Rand.Int (3, 5) %randmize the speed of drops rain

end if

Draw.ThickLine (round (Particles (i).x), round (Particles (i).y), round (Particles (i).x), round (Particles (i).y + (Particles (i).speed)), 5, blue) %draw the drop of rain

Draw.ThickLine (round (Particles (i).x), round (Particles (i).y), round (Particles (i).x), round (Particles (i).y + (Particles (i).speed)), 4, white) %draw the drop of rain

end for
View.Update
end loop





Please specify what version of Turing you are using
Turing 4.0.4c
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Fri Nov 12, 2010 11:52 am   Post subject: RE:Running and stopping a particle script, without ending the whole program

Turing:

var programFlag, particleFlag : boolean := false
loop
    exit when programFlag


    loop
        exit when particleFlag or programFlag

        particleFlag := true %When you want to exit the particle loop
        programFlag := true %When you want to exit the program
    end loop
end loop



Nested loops are da-bomb. Understande?
DemonWasp




PostPosted: Fri Nov 12, 2010 11:54 am   Post subject: RE:Running and stopping a particle script, without ending the whole program

It is plain that you do not understand the code you've posted. If you did, you'd know that all you need to do is keep a "count" variable that increments each time you go through the loop labeled "main animation loop" and exit when it hits a given number (probably at least a few hundred).

The only other potential issue I can see is that the display will not automatically update itself, so put commands and the like will not show up until you do a View.Update().
Zren




PostPosted: Fri Nov 12, 2010 12:06 pm   Post subject: RE:Running and stopping a particle script, without ending the whole program

Oh woops. >.<
Re-read the question in the post instead of the topic title. Totally misinterpreted the question.

As much as I do think the above is copy pasta, I disagree with the counting idea. Formally checking with the Time.Sec() would be a better alternative since it allows it to be a standard wait across all computers.

You'd start with checking the time as you go into the particle engine, then every rendering of the engine, check if it's been x time since the start, and exit the loop.

Eg:
Turing:


var start := Time.Sec
loop
    exit when Time.Sec >= start + 5
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  [ 4 Posts ]
Jump to:   


Style:  
Search: