Page 1 of 1

startscript isn't starting the script

PostPosted: Tue May 05, 2009 4:23 pm
by miran
This is the script I'm trying to start. Obviously it's a test. It will run from the console, so I know it's loaded and I know it works.

Code: Select all
begin m_test

messagebox, "start script test"

end m_test


This is the while statement I'm using to start/stop the script.

Code: Select all
       while ( dewonce == 0 )
               set dewonce to 1
               startscript, "m_test"
               messagebox "shall I continue?" "okay"
               stopscript, "m_test"
       endwhile


The message box "shall I continue" displays just fine, and the commands before and after this while statement also work properly. I take that to mean that the while statement IS being processed.

What idiot mistake am I making?

Re: startscript isn't starting the script

PostPosted: Tue May 05, 2009 5:25 pm
by Jac
I'd move the stopscript command into the m_test script. That way the script will stop itself. I don't think that's the problem, but it can't hurt to try. :smile:

Re: startscript isn't starting the script

PostPosted: Tue May 05, 2009 5:59 pm
by peachykeen
I think it could be. See, scripts are run in order, one at a time (usually). Each frame, each script gets run.
Your script A is starting script B and stopping it in the same frame. B never gets a chance to run. Wait one frame between starting and stopping B (a state variable and return) and it should work.

Re: startscript isn't starting the script

PostPosted: Tue May 05, 2009 8:17 pm
by miran
Jac & pachykeen: It worked. I got both messages. But that actually leaves me a bit confused.  :chinscratch:

What I had expected (from the way I had it set up initially) was that I would get a continuous generation of the message box from script B. Then, after stopping it with the console, it would finish up the rest of the script.

I thought that the message box with a button (inside the while statement) would be enough to get from one frame to another. Or does it actually stop the clock, freezing the frame? (could have sworn things keep moving in the background ... will have to check)

Also, I thought that running through a while statement 'kicks' you to the next frame ... is that it? It might work if I put the stopscript after the while statement?

Re: startscript isn't starting the script

PostPosted: Wed May 06, 2009 4:04 pm
by peachykeen
Scripts aren't like functions. They can't be chained off and return, they each run through once per frame.

Buttons lock the screen until an option is selected.

While statements won't help, not really. You can use state variables better. While in Morrowind is best used sparingly.

Re: startscript isn't starting the script

PostPosted: Wed May 06, 2009 5:28 pm
by Jac
Like Peachy pointed out, it's best to have a state variable to get button presses:

Code: Select all
short controlVar

if ( controlVar == 0 )
     MessageBox "<text>" "<option 1>' "<option 2>" etc.
    set controlVar to 1
endif

if ( controlVar == 1 )
       set button to GetButtonPressed
       if ( button == -1 )
               return
       elseif ( button == 1 ) ;first button
           set controlVar to 2 ;or reset to zero if you want to run the messagebox again.
          endif
endif

Re: startscript isn't starting the script

PostPosted: Wed May 06, 2009 5:34 pm
by peachykeen
I myself would do this with the code, instead:
Code: Select all
if ( controlVar == 0 )
     MessageBox "<text>" "<option 1>' "<option 2>" etc.
    set controlVar to 1
elseif ( controlVar == 1 )
  set button to GetButtonPressed
  if ( button == -1 )
     return ; cuts off execution here and starts from the top next frame
  elseif ( button == 0 ) ;first button, zero-based index
           set controlVar to 2 ;or reset to zero if you want to run the messagebox again.
  endif
endif

Re: startscript isn't starting the script

PostPosted: Wed May 06, 2009 8:18 pm
by miran
First: I'm sorry. You're being helpful, and I'm starting to twitch. It's very rude of me. This is a poor way of saying thank you to both of you. Better way: Thank you. (another forum I'm on has smilies that give ice-cream cones, cakes, and drinks with umbrellas [there's one with a mini-bar even]: please pick the intent that most pleases you. Patience, at least in others, is an admirable quality.)

Note: I have gotten the script, startscript, the called script, etc., to work. Due entirely to the two of you. Thank you. (the message box was there for testing purposes only)

Second: I searched the MWSFD 9 for 'state variable' and got an error message. (can't find, or some-such; something I didn't want to see, regardless)

  GuessA: a state variable is where you test the value of a variable?

Third: When you say function: I'm taking it to mean a defined series of instructions that's available by typing a command word -- in effect a short 'call a function (mini-script) and return'. Since my scripting world is tilting on it's axis, I'd guess that's wrong, though it seems quite reasonable.  :banghead:

Fourth: I'm still confused about how scripts run. My guess: Script A to point 01, call ScriptB, run ScriptB to end, return to ScriptA point 1-next line, finish the rest of ScriptA. What you're saying indicates that that is wrong.

Fifth: Every global script, any script that isn't attached to an object and not declared as a start-script, runs continuously? Once per frame? Really? ... That seems less than efficient. (and probably why Balmora, with all my currently active mods, slows to 7 fps) (ack) (really awful and really inefficient) If that's the case, there's no point putting a 'startscript' anywhere other than just before the end of a script.

While this all results from my first question, if I should break this up, just say so. (if I knew enough to know what answers the question I'd have the answer already)

Re: startscript isn't starting the script

PostPosted: Wed May 06, 2009 9:11 pm
by Fliggerty
Second: I searched the MWSFD 9 for 'state variable' and got an error message. (can't find, or some-such; something I didn't want to see, regardless)

GuessA: a state variable is where you test the value of a variable?

A state variable isn't really a type of variable; rather it's just the way you use it.  Think of it as simply a way to break a script up into different parts, each of which runs individually.  Something like this:
Code: Select all
short state

if ( state == 0 )
    ;do something
    set state to 1
elseif ( state == 1 )
    ;do something else
    set state to 2
else
    ;do something else again
endif


Third: When you say function: I'm taking it to mean a defined series of instructions that's available by typing a command word -- in effect a short 'call a function (mini-script) and return'. Since my scripting world is tilting on it's axis, I'd guess that's wrong, though it seems quite reasonable.

A function is what we use to get data from or give data to the engine.  GetHealth, SetHealth, MessageBox, and MenuMode are all examples of functions.

Fourth: I'm still confused about how scripts run. My guess: Script A to point 01, call ScriptB, run ScriptB to end, return to ScriptA point 1-next line, finish the rest of ScriptA. What you're saying indicates that that is wrong.

Every script that has been started previously will run once in each frame; it won't move to the next frame until all scripts are complete.  When you start a script, it is only queued up until the next frame, when it will actually run, and keep running until it is stopped.

Fifth: Every global script, any script that isn't attached to an object and not declared as a start-script, runs continuously? Once per frame? Really? ... That seems less than efficient. (and probably why Balmora, with all my currently active mods, slows to 7 fps) (ack) (really awful and really inefficient)

Yup.  Actually in Balmora it's likely that the AI as well as the scripts is the main culprit.

If that's the case, there's no point putting a 'startscript' anywhere other than just before the end of a script.

Well, no, not really.  It all depends on your script structure, you put the StartScript wherever the logic of your script needs it to be.  This brings us back to that state variable.

Re: startscript isn't starting the script

PostPosted: Sun Jun 07, 2009 8:19 pm
by miran
Thank you for all this!

Fliggerty wrote:A state variable isn't really a type of variable; rather it's just the way you use it.  Think of it as simply a way to break a script up into different parts, each of which runs individually.  Something like this:
Code: Select all
example

Okay and thanks for the example.
.A function is what we use to get data from or give data to the engine.  GetHealth, SetHealth, MessageBox, and MenuMode are all examples of functions.

Okay, that's good.
Every script that has been started previously will run once in each frame; it won't move to the next frame until all scripts are complete.  When you start a script, it is only queued up until the next frame, when it will actually run, and keep running until it is stopped.

So you can only start another script, you can't have the started script send back data (update a variable) that you need to finish the first script? Right?
Yup.  Actually in Balmora it's likely that the AI as well as the scripts is the main culprit.

Now, see, I know what AI is and still that comment stops me.
Well, no, not really.  It all depends on your script structure, you put the StartScript wherever the logic of your script needs it to be.  This brings us back to that state variable.

Does that mean you can 'cycle' a script from frame to frame if you need to get updated info to finish it?

Sorry for the delay in responding  :shrug:  the rest of my life.

Re: startscript isn't starting the script

PostPosted: Mon Jun 08, 2009 6:15 am
by Jac
To have a script change the variables in another script, you need to write it like this: set <script name>.<variable name>. For example, if the script's name is jac_myscript and the variable is doOnce, the command would be Set jac_myscript.doOnce to 1. Alternatively, you could use a global variable and have the script check to see what value is stored in it.

Re: startscript isn't starting the script

PostPosted: Mon Jun 08, 2009 8:18 am
by miran
Jac wrote:To have a script change the variables in another script, you need to write it like this: set <script name>.<variable name>. For example, if the script's name is jac_myscript and the variable is doOnce, the command would be Set jac_myscript.doOnce to 1. Alternatively, you could use a global variable and have the script check to see what value is stored in it.

Oh, that's very cool. Does that automatically start the other script or is that variable stored till needed?

Am I right that this is one way?

Thank you.

Re: startscript isn't starting the script

PostPosted: Mon Jun 08, 2009 8:29 am
by Jac
No, it just stores the variable if the script is already running. Startscript is the only way to stat a script via another script.

Re: startscript isn't starting the script

PostPosted: Mon Jun 08, 2009 8:40 am
by miran
Jac wrote:No, it just stores the variable if the script is already running. Startscript is the only way to stat a script via another script.

Okay, then. Thank you.