setting local variables in the console

General discussion regarding the OpenMW project.
For technical support, please use the Support subforum.
Post Reply
User avatar
asmo
Posts: 229
Joined: 18 Sep 2014, 21:20

setting local variables in the console

Post by asmo »

It often happens that I want to test a script in different circumstances or just find out what happens how and when.

Code: Select all

MessageBox "%f" ("Caius Cosades"->GetDistance player) "ok"
It needs to be taken care of that the MessageBox command is not executed in every frame.

A way to do this is the "famous" doOnce variable. When I reached a situation I want to test the script again I need to save and reload.
It would be nice to have somehting like

Code: Select all

set "Caius Cosades".doOnce to 1
Only one script can be attached to an entity so the variable to set could clearly be addressed.

Of course it would affect all instances of an object (NPC, cloth ...) but that's true for a script itself. This idea gives some flexibility for developers and modders when "exploring the game".
User avatar
asmo
Posts: 229
Joined: 18 Sep 2014, 21:20

Re: setting local variables in the console

Post by asmo »

Other use cases:

Code: Select all

set <NPC>.companion to {0,1}
set <NPC>.stayoutside to {0,1}
This would require that companion, sayoutside... do not need to be declared for scripts that are attached to NPCs.
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: setting local variables in the console

Post by scrawl »

Code: Select all

set "Caius Cosades".doOnce to 1
AFAIK, that's already implemented, just like vanilla Morrowind requires it.
User avatar
asmo
Posts: 229
Joined: 18 Sep 2014, 21:20

Re: setting local variables in the console

Post by asmo »

Then something is wrong.

Code: Select all

short doonce
if ( doonce == 0 )
    if ( ( GetDistance player ) < 8000 )
        MessageBox "%f" ( GetDistance player ) "ok"
    endif
endif
set doonce to 1
> PlaceAtPC "Caius Cosades" 1 1 1
MessageBox appears: 0.997196 "ok"
> "Caius Cosades".doonce
0
> MessageBox "%f" "Caius Cosades".doonce
0
> set "Caius Cosades".doonce to 1
> "Caius Cosades".doonce
1
> set "Caius Cosades".doonce to 0
The GetDistance-MessageBox should be displayed at least here.

It looks like setting the local variable is either ignored by the script (engine) - or the way of addressing does not access (get/set) the variable in the script.
At the end of the "first" execution doonce is 1, not 0 as shown above.
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: setting local variables in the console

Post by Zini »

File a bug report please.
User avatar
asmo
Posts: 229
Joined: 18 Sep 2014, 21:20

Re: setting local variables in the console

Post by asmo »

Ok, thx
Golken
Posts: 27
Joined: 04 May 2015, 05:03

Re: setting local variables in the console

Post by Golken »

Just to make certain that you're aware, you could use a timer (seconds counter) or a frame counter to prevent the MessageBox from appearing every frame (having it appear periodically, instead). It should be far more convenient than a doOnce flag in many debugging situations.
When dealing with a global script, it's also a possibility to put "StopScript scriptname" at the top of it, then it will only ever execute once every time it is started.
User avatar
asmo
Posts: 229
Joined: 18 Sep 2014, 21:20

Re: setting local variables in the console

Post by asmo »

Golken wrote:Just to make certain that you're aware, you could use a timer (seconds counter) or a frame counter to prevent the MessageBox from appearing every frame (having it appear periodically, instead). It should be far more convenient than a doOnce flag in many debugging situations.
When dealing with a global script, it's also a possibility to put "StopScript scriptname" at the top of it, then it will only ever execute once every time it is started.
I knew, thanks. :)
I wanted to test until which distance a fireball hits an NPC, at which distance it will shout and at which come for you.
As well, at a certain distance (above the players head) objects vanish. So a frame-/time- based approach would not have been so helpful here. Yes I could have scripted that, but I would have needed a plain surface and put some more work than by a "show distance now"-script.
The StopScript command is what I didn't think of. Thanks again
Post Reply