[01 Jun 2010] Repeat WaitEvent

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
Tommi

[01 Jun 2010] Repeat WaitEvent

Post by Tommi »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Tue, 1 Jun 2010 15:23:47 -0700 (PDT)

Hello, New on the list, hello everybody.

I need help with this:

Code: Select all

Repeat
	WaitEvent
Forever
Well, this works, but how to terminate, so it will continue with code after this?

I would like to replace Forever with "run untill left mouse button is pressed",

Something like this:

Code: Select all

Repeat
            Wait(2)
Until IsLeftMouse() = True
But instead of "wait" --- "run" (run as long IsLeftMouse() = False

Any ideas?

Regards Tommi
PEB
Posts: 569
Joined: Sun Feb 21, 2010 1:28 am

[01 Jun 2010] Re: Repeat WaitEvent

Post by PEB »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Tue, 01 Jun 2010 23:21:15 -0000

You probably want to install an event handler to manage what happens when the Left Mouse Button is pressed. Try this:

Code: Select all

Function p_LeftMouseFunc()
	DebugPrint("The Left Mouse Button has been pressed (and released).")
EndFunction
InstallEventHandler({OnMouseUp=p_LeftMouseFunc})
Repeat
	WaitEvent
Forever
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

[02 Jun 2010] Re: Re: Repeat WaitEvent

Post by Bugala »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 2 Jun 2010 06:43:18 +0300 (EEST)

Personally i usually use something like this in my own programs:

Code: Select all

Var_StopRuning = 0
repeat
wait(2)
until Var_StopRuning = 1
some more code...
this way i can have several reasons to stop the program (ie end of level) and continue it.

So then you would put for example that revs Function in way of:

Code: Select all

Function p_LefmouseFunc()
Var_StopRuning = 1
EndFunction
nexus
Posts: 133
Joined: Sun Mar 07, 2010 11:54 am

[02 Jun 2010] Re: Repeat WaitEvent

Post by nexus »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 02 Jun 2010 05:54:27 -0000

You don't need to poll the variable "Var_StopRunning" permanently (and that's also not recommended anyway). An event, like a mouse click, causes your program to leave its Wait()-state anyway. Therefore try this:

Code: Select all

Var_StopRuning = 0
repeat
wait()
until Var_StopRuning = 1
some more code..
It does the same but only checks the "until"-condition when indeed there's an event. Of course, you still need to specify p_LeftmouseFunc() as an event function.

@Tommi Toivanen

However, if you only want to wait for a mouse click, then just use the command:

WaitLeftMouse()

There's no need for a loop. It's hidden within that command already :-)

I recommend to read the (very well written) "Hollywood Guide" (located in the Hollywood directory) and especially its tutorial part to get familiar with all the possibilities the language provides to you.

regards, Tom
nexus
Posts: 133
Joined: Sun Mar 07, 2010 11:54 am

[02 Jun 2010] Re: Repeat WaitEvent

Post by nexus »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 02 Jun 2010 06:00:07 -0000

You don't need to poll the variable "Var_StopRunning" permanently (and that's also not recommended anyway). An event, like a mouse click, causes your program to leave its Wait()-state anyway. Therefore try this:

Code: Select all

Var_StopRuning = 0
repeat
WaitEvent()
until Var_StopRuning = 1
some more code..
It does the same but only checks the "until"-condition when there's indeed an event. Of course, you still need to specify p_LeftmouseFunc() as an event function.

@Tommi Toivanen

However, if you only want to wait for a mouse click, then just use the command:

WaitLeftMouse()

There's no need for a loop. It's hidden within that command already :-)

I recommend to read the (very well written) "Hollywood Guide" (located in the Hollywood directory) and especially its tutorial part to get familiar with all the possibilities the language provides to you.

regards, Tom
nexus
Posts: 133
Joined: Sun Mar 07, 2010 11:54 am

[02 Jun 2010] Re: Repeat WaitEvent

Post by nexus »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 02 Jun 2010 06:10:49 -0000

Argh!

It seems I have to read some tutorials how to *use* the Yahoo! Groups mailing list Web form :-) I have no clue why i posted my message twice and why this text above has appeared in the second message. Acutally, I just wanted to edit my message because you have of course to use "WaitEvent()" instead of "Wait()" within the loop.

So, please ignore my first (and this third message) and also the lines above within my second message ;-)

sigh, Tom
User avatar
TheMartian
Posts: 109
Joined: Sun Feb 28, 2010 12:51 pm

[02 Jun 2010] Re: Repeat WaitEvent

Post by TheMartian »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 02 Jun 2010 18:38:13 -0000

Hi

Whenever I start coding a new program the first code I put in is this...

Code: Select all

System={runFlag=True}

/* 
Here goes all the code for the program. usually in the form of 
@INCLUDE statements where each statement includes code for a specific object class apart from the final included file which includes a file with the code to initialize the program.
*/

While System.runFlag
WaitEvent
Wend

End
Then at any time the program can be stopped by simply setting System.runFlag to False somewhere in the code and call that bit of code when appropriate.

Of course it is a matter of taste which method you use to terminate your main loop. I just happen to like this one because I don't have to decide right away what condition is required to trigger the end of the program. Besides it allows me to define multiple conditions for ending the program.

regards Jesper
Tommi

[02 Jun 2010] SV: Re: Repeat WaitEvent

Post by Tommi »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 2 Jun 2010 22:59:54 -0700 (PDT)

Hello, thank you everyone for suggestions. Tried different things, and the one that seems to work best for me, is the System={runFlag=True} idea from Jesper.

It does indeed continue into a slideshow, but still one problem remaining. On the initial intro screen I have bouncing balls, and that was the loop I wanted to break. Before System={runFlag=True}, the balls just kept on bouncing, now it continues, but the balls remain, so the bounce balls loop is still not halted. I use sprites, maybe that is the problem? (Brushes instead?) Afrer a System={runFlag=False} break the brushes disappear with Cls, and the slideshow does start, but the sprites (bouncing balls), remain.

Regards /Tommi
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[03 Jun 2010] Re: SV: Re: Repeat WaitEvent

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Thu, 03 Jun 2010 22:19:23 +0200
Hello, thank you everyone for suggestions. Tried different things, and the one that seems to work best for me, is the System={runFlag=True} idea from Jesper.

It does indeed continue into a slideshow, but still one problem remaining. On the initial intro screen I have bouncing balls, and that was the loop I wanted to break. Before System={runFlag=True}, the balls just kept on bouncing, now it continues, but the balls remain, so the bounce balls loop is still not halted. I use sprites, maybe that is the problem? (Brushes instead?) Afrer a System={runFlag=False} break the brushes disappear with Cls, and the slideshow does start, but the sprites (bouncing balls), remain.
Hmm, does calling RemoveSprites() help?
Tommi

[03 Jun 2010] Re: SV: Re: Repeat WaitEvent

Post by Tommi »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Thu, 3 Jun 2010 23:48:16 -0700 (PDT)

Hello, no, tried both RemoveSprites() and RemoveSprite(number), but it did not help. Anyway, found a solution. After the bouncing ball loop I had a picture slidehow, so when I changed the picture slide to individual pictures loaded as brushes, the System={runFlag=True} (false), works. So, an uglier solution, but it works.

Regards Tommi

P.S. Kudos for sponsoring AWompetition2 :)
Locked