[Ohrrpgce] arguments vs locals
Bob the Hamster
Bob at HamsterRepublic.com
Tue Jun 7 08:18:24 PDT 2005
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))
> Anyway, yes scrap the argument to newgame script. A demo script it is.
>
> But what about the newgame/quit options on the load game screen?
What about them?
---
Bob the Hamster
> On 6/7/05, Bob the Hamster <Bob at hamsterrepublic.com> wrote:
> > On Sun, Jun 05, 2005 at 02:04:47AM +1200, TeeEmCee wrote:
> > > Also, some script calls (as in, npc triggered, autoload map scripts,
> > > etc) allow you to pass arguments to the scripts. Looking at the
> > > source, I realise that I was mistaken the whole time that if you don't
> > > want them, you don't have to declare arguments on the script? It seems
> > > that if you do this, they will get placed in local variables. I wanted
> > > to have true or false passed to the newgame script depending on
> > > whether the player pressed a key at the title (above), this might
> > > interfer with newgame scripts with locals, would this be a problem?
> >
> > Yeah. plotscripting does not really distinguish between arguments and
> > locals. This may have been a bad design decision, but that is the way
> > it works. If you want to add an auto-argument to the new game script,
> > that is okay, since script authors should really be initializing their
> > locals.... (mmmm... not that anybody knows that)
> >
> > Although, as I wrote in another post, I prefer having a separate "demo"
> > plotscript to be run instead of the new-game script, rather than adding
> > an true/false auto-argument to the new game script.
> >
> > You know, enforcing the separation of arguments and local variables
> > would not really be hard. The script-triggering code in the "runscript"
> > function in moresubs.bas needs some clean-up anyway. It could make sure
> > that locals will always be pre-inited to zero's. This would break the
> > scripts of anyone who is already depending on the current undocumented
> > "undeclared arguments overflow into locals" behaviour, but hopefully
> > nobody is doing that.
More information about the Ohrrpgce-motherhamster.org
mailing list