Difference between revisions of "Simulating new functions"
More function call options
imported>Kkuhlmann |
imported>Tegid (More function call options) |
||
Line 83: | Line 83: | ||
--[[User:Kkuhlmann|Kkuhlmann]] 14:02, 18 April 2006 (EDT) | --[[User:Kkuhlmann|Kkuhlmann]] 14:02, 18 April 2006 (EDT) | ||
I've been doing this for awhile now with OnActivate functions placed on activators. The reference you use to activate it acts as a parameter to tell it how to act. Then when that function is done it activates the calling object to let it know that it is finished and it is time to process the results. | |||
So for instance | |||
<pre>scn ActivateFunction | |||
ref incoming | |||
begin OnActivate | |||
set incoming to GetActionRef | |||
if (incoming == CallingScriptRef.Me) | |||
set CallingScriptRef.Value to CallingScriptRef.Value + 3 | |||
CallingScriptRef.Activate CallingScriptRef.ActivateFunctionRef 1 | |||
return | |||
endif | |||
end</pre> | |||
<pre>scn CallingScript | |||
ref Me | |||
ref ActivateFunctionRef | |||
long Value | |||
ref incoming | |||
begin OnLoad | |||
set Me to GetSelf | |||
set Value to 0 | |||
Message "I am storing a value of %.0f", Value, 1 | |||
end | |||
begin OnActivate | |||
set incoming to GetActionRef | |||
if (incoming == ActivateFunctionRef) | |||
Message "Now I am storing a value of %.0f", Value, 1 | |||
return | |||
endif | |||
ActivateFunctionRef.Activate Me 1 | |||
end | |||
</pre> | |||
This removes the need for a game mode block and allows function passing (or setting in a persistent reference). I've used this quite successfully for some cool stuff I'm finishing the testing on. | |||
--[[User:Tegid|Tegid]] 14:44, 18 April 2006 (EDT) | |||
[[Category:Questions]] | [[Category:Questions]] |