[Ohrrpgce] arguments vs locals

Bob the Hamster Bob at HamsterRepublic.com
Tue Jun 7 09:34:35 PDT 2005


On Tue, Jun 07, 2005 at 08:18:24AM -0700, Bob the Hamster wrote:
> On Wed, Jun 08, 2005 at 02:04:51AM +1200, TeeEmCee wrote:
> > Hmmm? Runscript does initialise all arguments and locals to zero:
> > 
> > FOR i = 1 TO scrat(index, scrargs)
> >  heap(scrat(index, scrheap) + (i - 1)) = 0
> > NEXT i
> > 
> > However, when arguments are passed to a script, this happens after
> > runscript has loaded and cleared its locals, then arugments might
> > overflow into variables.
> 
> Absolutely right! I had forgotten how it worked.
> 
>  rsr = runscript(gmap(13), nowscript + 1, -1, "rand-battle")
>  IF rsr = 1 THEN
>   heap(scrat(nowscript, scrheap)) = batform
>   heap(scrat(nowscript, scrheap) + 1) = temp
>  END IF
> 
> Perhaps it would be best to add a sub like "setScriptArg"
> 
>  rsr = runscript(gmap(13), nowscript + 1, -1, "rand-battle")
>  IF rsr = 1 THEN
>   setScriptArg 0, batform
>   setScriptArg 1, temp
>  END IF
> 
> Where setScriptArg would first check to see if the script is allowed 
> arguments, and then would set the specified value in 
> heap(scrat(nowscript, scrheap))

Okay, I just did exactly that. it iss now safe to assume that your local 
script variables will start out set to zero. Automatically supplied 
arguments will only be assigned to scripts that are capable of accepting 
them as arguments.

---
Bob the Hamster



More information about the Ohrrpgce mailing list