User Tools

Site Tools


4rpl:commands:registerscript

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
4rpl:commands:registerscript [2022/05/10 17:53] – cross-ref Karsten754rpl:commands:registerscript [2022/05/12 12:01] (current) Karsten75
Line 1: Line 1:
 ~~NOTOC~~ ~~NOTOC~~
-<=[[4rpl:start| Index]]+<=[[4rpl:start| Index]] \\ 
 +<= [[4rpl:start#Messaging]] 
  
 :!: Available in version 1.3 and later. :!: Available in version 1.3 and later.
Line 7: Line 8:
  
 ===== Description ===== ===== Description =====
-Registers the current script instance with a name. This name can be used with [[GetRegisteredScriptVar]]. If the same name is used as another script instance, this call will deregister the other script instance and replace it with the new one. A script on a unit in a unique instance. Each global script instance is also unique. +Registers the current script instance with a name. This name can be used with [[GetRegisteredScriptVar]]. If the same name is used as another script instance, this call will deregister the other script instance and replace it with the new one. A script on a unit is a unique instance. Each global script instance is also unique. 
  
 :!: Note that registering a script is NOT persistent. It will not be saved in a save game file. You must reregister a script. :!: Note that registering a script is NOT persistent. It will not be saved in a save game file. You must reregister a script.
Line 18: Line 19:
 === See Also === === See Also ===
 [[DeregisterScript]] [[DeregisterScript]]
 +
 +=== Discussion ===
 +This was added to CW4 as an attempt to give a similar API to what was in CW3.  [[|Messaging]] is likely the better option in most cases.
 +
 +This works a lot like messaging.  There is a global map and RegisterScript adds an entry into that map with the name you specify and the script it is called from.  So it stores a named reference to a script instance in a global map,  Get/SetRegiseredScriptVar looks up that instance in the map and then Gets/Sets a var on it.  So if you have a Foo script attached to Unit A and Foo calls RegisterScript("AName"), that will be a problem if another instance of Unit A runs Foo and it does the same thing.  So Foo would more likely call RegisterScript("AName:" self concat) or something like that.  And the only reason it would ever call RegisterScript would be so some other script could get/set some variable on it 
 +
 +It makes most sense in a scenario where there is a single global script.  Maybe "MapController" That script calls RegisterScript("MapController").  Then other scripts anywhere can call Get/SetRegisteredScriptVar("MapController" ...)
  
 <=[[4rpl:start| Index]] <=[[4rpl:start| Index]]
4rpl/commands/registerscript.1652219598.txt.gz · Last modified: 2022/05/10 17:53 by Karsten75