Eric Walch wrote:It want just to confirm that the local-variable bug(s) in 1.69 as mentioned above is solved.
I was writing a test-script by setting a local variable in one OXP and use it in an other OXP. It didn't work. (it works with mission_variables).
Looking in the code I noticed local_variables are really what the name says: LOCAL. (Stupid me to think that a variable with a name local would work globaly.) Every mission reads in their own local variables. So you don't have to worry that other oxp's could use the same variable name with local variables. (e.g. local_test can be safely used as variable within an oxp) This was not mentioned explicitly in the WIKI. (I always thought the only difference with mission-variables was that they were not stored.)
I have to watch for this. UPS-courier.oxp defines internally 5 separate missions within one OXP and the variables are only valid within each separate mission, not within the total OXP when I interpret things right.
In my previous UPS version I used local variables in a barrel scooping mission. Every time a NPC ship scooped one the variable was increased and the value was presented to the player with a console message. Thinking of this, it was a bug that is worked, as barrels (or ships) have no link with a certain mission. They are not really local when they are shared among script_actions of different barrels. In UPS version 1.2 I changed them into mission_variables that work well in Oolite 1.70.
But in 1.70 script_actions can also not deal with local variables within a script as submitted as bug elsewhere.
I think it was mentioned somewhere (though perhaps only during a discussion here on the board) that local_variables are local and therefore only valid within one script. So I was never confused about that.
In Anarchies.oxp I am using local_variables a lot, basically because I am just manipulating things like
legalStatus_number, and in the end of each action the final value is returned to that by the
setLegalStatus method. So no need to store anything anywhere, no need to exchange values with other scripts, and no need for any traces in the player's save-file (I find it ugly to put up a lot of mission-variables and leave them in the save-file forever, but that's only a question of personal taste, I guess; therefore I think that each script, when everything is said and done, should reset all its mission_variables except the main variable, named after the mission (like mission_deposed or mission_trumbles)).
What I was wondering about during these last days was whether local_variables are stored
anywhere? Let's say a variable like local_jumpcount counts the number of jumps the player has made in the context of a certain mission. Now, I'd like to know what happens to this local_jumpcount, if the player decides to save his game, loads another game, plays for a while, and then reloads the first game. Will local_jumpcount still have the same value? Or will it be undefined again? And what happens if the player doesn't just reload the old game, but quits and restarts the program (although I guess that in this case all local_variables are gone)?
Would be nice to get answers to these questions, if you have already dug deep enough to know them, Eric.