sm00thslp / hedgewars

Automatically exported from code.google.com/p/hedgewars
GNU General Public License v2.0
0 stars 0 forks source link

Script parameters are not available in onPreviewInit, but should #873

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Well, it appears to me that it is not possible to access the script parameters 
within onPreviewInit, which is a bummer, since that means while you could 
configure Lua-generated maps at will, you will not be able to show a correct 
preview for parameters other than the default. So there is a very good reason 
to make the parameters available to onPreviewInit.

You can test this for yourself, but this slightly tricky:

First, create a multiplayer script called “ScriptParamTest.lua” containing 
this test code:

-- snip --
function onPreviewInit()
    if ScriptParam == nil then
        print("__LUATEST__: ScriptParam == nil")
    else
        print("__LUATEST__: ScriptParam ~= nil")
    end
end
-- snip --

Also create ScriptParamTest.cfg with two lines containing “Default” each so 
you can edit the schemes.

Then create a simple test game scheme where you write anything into the script 
parameter field. I don’t know if this step is important.

Lastly, start Hedgewars but make sure you write the Standard error stream 
(stderr) into a file. I had to use print because WriteLnToConsole does not work 
inside onPreviewInit. Then simply start a game using this script and your test 
game scheme and leave Hedgewars as soon as the game has been loaded. Now look 
into the file you used for logging and search for the string “__LUATEST__”. 
This line will tell you wheather ScriptParam equalled nil.

For me, ScriptParam equalled nil. To make sure I made no stupid flaws in my 
tests, I also quickly checked the contents of this variable in onParameters, 
and of course in this function this variable contained the actual string.

I tested this on ra88647ead05c under GNU/Linux.

Original issue reported on code.google.com by almikes@aol.com on 19 Dec 2014 at 8:20