Page 1 of 1

Anyway to make Function calculations already when formed?

Posted: Sun Mar 22, 2020 9:17 pm
by Bugala
Dont know what word to use, but what I want to do on fly is to make functions calculations done already when formed

I have this situation where I am trying to put to "OnMouseOver = Function() stuff EndFunction"

where I want part of that "stuff" to be decided at that point already. Let me give you an example:

Code: Select all

for n = 1 to 5
...
MakeButton... OnMouseOver = Function()
				result = n+1
			endfunction)
What I want to make here is to make 5 buttons, and when mouseover happens, I want it to happen so that on first button result = 2, second button result = 3 etc.

however, in practice what happens in here is that each button gives same result, since result depends upon what the result of "n" happens to be at that time in program.

Is there a way to do this is such way that the result would be made already at this point to become n+1, instead of it being calculated at point when mouseover happens?

Re: Anyway to make Function calculations already when formed?

Posted: Sun Mar 22, 2020 11:12 pm
by lazi
I think you can achieve something similar with the MakeButton's userdata.

Check this:

Code: Select all

Function p_button(msg)
	DebugPrint(msg.userdata)
EndFunction


x=1

MakeButton(1,#SIMPLEBUTTON,10,10,300,30,{OnMouseover=p_button},x)

x=23

MakeButton(2,#SIMPLEBUTTON,10,100,300,30,{OnMouseover=p_button},x)


Repeat
	WaitEvent
Forever
                

Re: Anyway to make Function calculations already when formed?

Posted: Sun Mar 22, 2020 11:55 pm
by Bugala
Yeah, that is actually how I solved it myself in the end after having written here, but was wondering if there would be some simpler way.
Especially if there happens to be more than one cemented value, it might end up having to send more than one userdata.

But thanks for giving suggestion.