[07 Jan 2010] Can buttons be used without waitevent?

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
Bugala
Posts: 935
Joined: Sun Feb 14, 2010 7:11 pm

[07 Jan 2010] Can buttons be used without waitevent?

Post by Bugala »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Thu, 07 Jan 2010 01:48:02 -0000

Problem is this.

I made a button that i planned that whenever you push it, it does its function.

However, i noticed it doesnt react to click unless i use waitevent.

unfortunately, this is no use to me. For i want to use that button in middle of game.

Say as example, i would want some layer to present "Quit" button.

So that ingame when all stuff is moving on screen, if you push that button, it would end that game.

Is there anyway to do this by using buttons? For those buttons would be so handy way to do such things.

PEB
Posts: 536
Joined: Sun Feb 21, 2010 1:28 am

[06 Jan 2010] Re: Can buttons be used without waitevent?

Post by PEB »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 6 Jan 2010 18:01:33 -0800 (PST)

There is no problem here, because the movement of objects in your game would be governed by intervals and event-handlers.

Bugala
Posts: 935
Joined: Sun Feb 14, 2010 7:11 pm

[07 Jan 2010] Re: Can buttons be used without waitevent?

Post by Bugala »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Thu, 07 Jan 2010 11:47:10 -0000

Im still learning Hollywood yet, so you completely dropped me with your answer.

What do you mean by movement of your objects handled with event-handlers and intervals? (i mean, i do remember something like that from Amos and Blitzbasic, but what in Hollywood)

Currently im simply using:

Code: Select all

Showlayer("name", x, y)
How do i do that other thing you said?

By the way, your tip on RawGet() along with Hollywood4.5s x=layer(NIL, otherstuff) have dropped maybe 30 lines of code from my 300 lines currently (and theres lot of empty lines too)

So thanks a lot from that!

Bugala
Posts: 935
Joined: Sun Feb 14, 2010 7:11 pm

[07 Jan 2010] Re: Can buttons be used without waitevent?

Post by Bugala »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Thu, 07 Jan 2010 14:05:17 -0000

Ah, thakns Rev..

Thanks to you, i was able to find this CheckEvent() command that fixed the problem for me.

PEB
Posts: 536
Joined: Sun Feb 21, 2010 1:28 am

[07 Jan 2010] Re: Can buttons be used without waitevent?

Post by PEB »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Thu, 07 Jan 2010 17:29:29 -0000

OK, try this example code, and let me know if you have any questions about it:

Code: Select all

EnableLayers()

CreateBrush(1, 100, 100, #WHITE)
DisplayBrush(1, 0, #CENTER, {Name="MovingButton", Hidden=True})

ReverseVar=0
Function p_ButtonMove()
	If ReverseVar=0
		NewX=NewX+1
	Else
		NewX=NewX-1
	EndIf
	ShowLayer("MovingButton", NewX, #USELAYERPOSITION)
	If NewX>50 OR NewX<0 Then ReverseVar=Not ReverseVar
EndFunction

TextOut(#CENTER, 10, "Nothing has happened yet.", {Name="Info"})

Function p_ButtonFunc(msg)
	Switch msg.action
		Case "OnMouseOver":
			SetLayerStyle("Info", {Text="The Mouse is Over the Button."})
		Case "OnMouseOut":
			SetLayerStyle("Info", {Text="The Mouse is Off the Button."})
		Case "OnMouseDown":
			SetLayerStyle("Info", {Text="The Button is Pressed."})
		Case "OnMouseUp":
			SetLayerStyle("Info", {Text="The Button is Released."})
	EndSwitch
EndFunction

ButtonTable={OnMouseOver=p_ButtonFunc, OnMouseOut=p_ButtonFunc, OnMouseDown=p_ButtonFunc, OnMouseUp=p_ButtonFunc}

MakeButton(1, #LAYERBUTTON, "MovingButton", TRUE, TRUE, ButtonTable)

SetInterval(1, p_ButtonMove, 40)

Function p_CheckKeyPress(msg)
	If msg.key="UP"
		ShowLayer("MovingButton", #USELAYERPOSITION, GetAttribute(#LAYER, "MovingButton", #ATTRYPOS)-5)
	ElseIf msg.key="DOWN"
		ShowLayer("MovingButton", #USELAYERPOSITION, GetAttribute(#LAYER, "MovingButton", #ATTRYPOS)+5)
	EndIf
EndFunction

InstallEventHandler({OnKeyDown=p_CheckKeyPress})

Repeat
	WaitEvent
Forever
This code makes a moving button. The horizontal movement is handled by the interval; optional vertical movement can be added using the UP and DOWN arrow keys.

Making this example code for you did reveal a bug in Hollywood though---the MouseOver and MouseOut button events are only noticed if the mouse is moved, not if the button is moved under the mouse. (But this is not usually done anyway.)

PEB
Posts: 536
Joined: Sun Feb 21, 2010 1:28 am

[07 Jan 2010] Re: Can buttons be used without waitevent?

Post by PEB »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Thu, 07 Jan 2010 17:30:58 -0000

I would not use CheckEvent().

Refer to the example code that I sent you.

Bugala
Posts: 935
Joined: Sun Feb 14, 2010 7:11 pm

[08 Jan 2010] Re: Can buttons be used without waitevent?

Post by Bugala »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Fri, 08 Jan 2010 00:08:59 -0000

Ah, i see it much better now.

However, is there some big difference between using CheckEvent() or this interval system from executable point of view, or is the difference basically in programming?

Im just trying to avoid using this interval system at this point anymore, since i have alredy programmed this game quite far. And it seems by quick (if i understood right the idea of intervals) that to get most out of it, i should have thought about it right from beginning.

Thanks a lot from that text example, i was already having bit trouble in making good way to chage timers numbers, didint know i could just use SetLayerStyle() to simply change that text.

I thought there had to be such option somewhere, but hadnt found it, so was about to make text disappear and immediatelly replace it with new text layer in same place, but that hadnt been very good choice, so this is much better.

Oh, and neither did i know that using TextOut() i can also name that layer instantly wihtout being in need of using the SetLayerName().

Much better this way. Thanks a dozen Rev..

User avatar
airsoftsoftwair
Posts: 4392
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[09 Jan 2010] Re: Re: Can buttons be used without waitevent?

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Sat, 09 Jan 2010 01:01:57 +0100
Ah, i see it much better now.

However, is there some big difference between using CheckEvent() or this interval system from executable point of view, or is the difference basically in programming?
Well, CheckEvent() is basically the same as WaitEvent() except that it does not block. If there are no events to handle, CheckEvent() will return immediately. Check the Hollywood guide for more info... there are also informative sections about main loop design/ script timing issues.

Locked