Aller au contenu

Photo

Question on ExecuteScriptEnhanced


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
Ext3rmin4tor

Ext3rmin4tor
  • Members
  • 10 messages
I have to use this function, but I'm not sure I understood how it works.

1) Do AddScriptParameter calls need to be performed before invoking this function?

2) Can the object type parameter you pass to ExecuteScriptEnhanced be refered with OBJECT_SELF within the executed script?

Thanks in advance.

#2
Tchos

Tchos
  • Members
  • 5 086 messages
From what I gather, this function works by first setting some kind of global or local variable using AddScriptParameter, which ExecuteScriptEnhanced will then read back to use as the parameters for the script. So you need to use AddScriptParameter first, one for each parameter, in the order in which they should appear in the script's main function.

That's how I understand it.

I don't know the second answer, but OBJECT_SELF usually refers to the object that calls any particular script. If a script calls another script, then it's the object that the first script was called by.

Have you considered using an include file instead of ExecuteScript?

#3
Ext3rmin4tor

Ext3rmin4tor
  • Members
  • 10 messages
Yes, but I thought ExecuteScript launched the script in parallel, while if I call an included function it wil be sequencial. Is that correct?

#4
kevL

kevL
  • Members
  • 4 078 messages
not really. Both run sequentially, but the beauty of ExecuteScript() is how easy it is to have some other object ( OBJECT_SELF ) run it ...

#5
Tchos

Tchos
  • Members
  • 5 086 messages
kevL to the rescue!

Modifié par Tchos, 14 novembre 2012 - 10:32 .


#6
kevL

kevL
  • Members
  • 4 078 messages
i was bored ;)

#7
Ext3rmin4tor

Ext3rmin4tor
  • Members
  • 10 messages
kevL, so do you confirm that the object parameter passed to ExecuteScript can be accessed as OBJECT_SELF inside the script itself?

Also, I know in every game scripts run in pseudo-parallel but in truth they are sequencial, but with "sequential" do you mean pseudo-parallel or really sequential (that is, until the script called with ExecuteScript doesn't end the caller script doesn't go on)?

#8
kevL

kevL
  • Members
  • 4 078 messages

Ext3rmin4tor wrote...

kevL, so do you confirm that the object parameter passed to ExecuteScript can be accessed as OBJECT_SELF inside the script itself?

Yes. but don't take my word for it; put a line into the executed script:

SendMessageToPC(GetFirstPC(FALSE), "ObjectSelf : " + GetName(OBJECT_SELF));


Also, I know in every game scripts run in pseudo-parallel but in truth they are sequencial, but with "sequential" do you mean pseudo-parallel or really sequential (that is, until the script called with ExecuteScript doesn't end the caller script doesn't go on)?

well, i added this to my Heartbeat script ( nw_c2_default1 )

// added this so that if NPC has string_var "kL_sCalmHB" it will
// do those actions here. that script can set a local_int on the NPC
// to tell this script whether it should carry on completing or not.
string sCalmHB = GetLocalString(OBJECT_SELF, "kL_sCalmHB");
if (sCalmHB != "")
{
  ExecuteScript(sCalmHB, OBJECT_SELF);

  if (GetLocalInt(OBJECT_SELF, "kL_bStopHB"))
  {
    DeleteLocalInt(OBJECT_SELF, "kL_bStopHB");

    // note that this prevents the UserDefinedEvent from firing:
    return;
  }
}


The second part of that, Get/DeleteLocalInt, relies on the executed script to set that variable_int (or not) ... so someday if I get strange behavior it should show up. You can do a test yourself simply by putting in SendMessageToPC() debugs -- put one in the executed script and another in the calling script right below the ExecuteScript() command, and watch which message pops to chat window first

Also, note description: "Make oTarget run sScript and then return execution to the calling script." in nwscript.nss: then return execution to the calling script

( not that i really trust descriptions ..)


as to ExecuteScriptEnhanced(), remember it's just a convenience function. I tried it once, couldn't get it to work, but this was probably my own fault. The reason I didn't try too hard is because you can have a calling script set those ScriptParameter's as local_ints/strings/floats/objects on some available object, like the area or module, anyway and merely use ExecuteScript(). Then delete them in the exectuted script, right?