Anyway to make Function calculations already when formed?

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Anyway to make Function calculations already when formed?

Post 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?
User avatar
lazi
Posts: 627
Joined: Thu Feb 24, 2011 11:08 pm

Re: Anyway to make Function calculations already when formed?

Post 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
                
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: Anyway to make Function calculations already when formed?

Post 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.
Post Reply