In Freeciv 2.6.4, commands in the code section of a scenario .sav file run on load, before global vars are set to values shown in the scenario file. I ran across this issue because sav files were loading with nil values despite the vars being set in the scenario file [script]vars=$$ section.
To test this, set test=50 in vars section of scenario .sav file, and test=75 in code section of scenario file (example scenario file is attached to this post.)
![Image]()
^ Commands in code section run after clicking "OK"... but global vars are not set yet (see image below.)
![Image]()
^ Code section command has set test=75 BEFORE clicking "Start".
^ But pasting the command shown into client chat pane shows test=50, despite that code section commands have already run and set test to 75!
![Image]()
^ Then click start and turn 0 shows test=50 from vars! The 75 is just gone, replaced by value in vars once "Start" is clicked. (Or possibly before clicking "Start", since gtk2 client shows value at 50 despite it having just been set to 75 in code section.)
Test's value is initially nil prior to code section command to set it to 75. Then after clicking start test is 50.
To test this, set test=50 in vars section of scenario .sav file, and test=75 in code section of scenario file (example scenario file is attached to this post.)

^ Commands in code section run after clicking "OK"... but global vars are not set yet (see image below.)

^ Code section command has set test=75 BEFORE clicking "Start".

Code:
/lua log.error("%s","test=" .. tostring(test))

^ Then click start and turn 0 shows test=50 from vars! The 75 is just gone, replaced by value in vars once "Start" is clicked. (Or possibly before clicking "Start", since gtk2 client shows value at 50 despite it having just been set to 75 in code section.)
Code:
[script]vars=$test=50$code=$test=75log.error("%s","test=" .. tostring(test))function tester(turn, year)log.error("%s","tester: test="..tostring(test))endsignal.connect('turn_started', 'tester')tester(-1,-1)$
Statistics: Posted by Molo_Parko — Thu Aug 01, 2024 4:24 pm