The Gnats Lua questions (creating an event using lua)
Moderator: Forum Moderators
Re: The Gnats Lua questions (creating an event using lua)
I unfortunately received a stack traceback error "The local variable the_killer must be assigned before being used"
However my variable was assigned! I even proved so by displaying a message where the narrator says:
What would be causing this problem?
Here is a screenshot of the error:
However my variable was assigned! I even proved so by displaying a message where the narrator says:
"The killer = $the_killer.side"
What would be causing this problem?
Here is a screenshot of the error:
Creator of: The Reign of The Lords Era,The Gnats Franken Dungeon.
Re: The Gnats Lua questions (creating an event using lua)
That only means it exists as wml variable, not as Lua variable.The_Gnat wrote:I unfortunately received a stack traceback error "The local variable the_killer must be assigned before being used"
However my variable was assigned! I even proved so by displaying a message where the narrator says:"The killer = $the_killer.side"
By not using quotes, you ask variable to be evaluated.
Re: The Gnats Lua questions (creating an event using lua)
Sorry about confusion my exact code is this:
As you can see the message is Outside the Lua code. And the message confirmed that the variable the_killer was real and had a value.
Code: Select all
{MESSAGE_SPEAKER narrator (The killer: $the_killer.id & Side: $the_killer.side) ()}
[lua]
code=<<
local victoriousSide wesnoth.get_variable(the_killer.side)
for counter = 1, 3 do
if counter ~= victoriousSide then
wesnoth.sides[wesnoth.current.side].defeat_condition = "always"
end
end
>>
[/lua]
I will try doing it again with quotes:For simple variables I can say use quotes, for objects see reference.
local victoriousSide wesnoth.get_variable("the_killer.side")
Creator of: The Reign of The Lords Era,The Gnats Franken Dungeon.
Re: The Gnats Lua questions (creating an event using lua)
How am i this stupid!
Creator of: The Reign of The Lords Era,The Gnats Franken Dungeon.
Re: The Gnats Lua questions (creating an event using lua)
Hmm... I have added an "=" but it still gives the same error...
Spoiler:
Creator of: The Reign of The Lords Era,The Gnats Franken Dungeon.
Re: The Gnats Lua questions (creating an event using lua)
By not using quotes, you ask variable to be evaluated.
Re: The Gnats Lua questions (creating an event using lua)
Finnally!
Thank you ravana (very much) for helping me! The combination of problems (and my own stupidity) led me to spend far more time than it should have taken.
Finally working code:
Thank you ravana (very much) for helping me! The combination of problems (and my own stupidity) led me to spend far more time than it should have taken.
Finally working code:
Code: Select all
[lua]
code=<<
local victoriousSide = wesnoth.get_variable("the_killer.side")
for counter = 1, 3 do
if counter ~= victoriousSide then
wesnoth.sides[wesnoth.current.side].defeat_condition = "always"
end
end
>>
[/lua]
Creator of: The Reign of The Lords Era,The Gnats Franken Dungeon.
- Celtic_Minstrel
- Developer
- Posts: 2274
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: The Gnats Lua questions (creating an event using lua)
By leaving out the = you are telling Lua: "I want to declare a local variable victoriousSide and set it to nil. Then I want to get the value of $the_killer.side but do nothing with it." In effect, Lua thinks you've just put two commands on the same line, rather than one command to get $the_killer.side and assign its value to victoriousSide.
Re: The Gnats Lua questions (creating an event using lua)
Yes i realized i needed a "=" but for some (stupid) reason i kept forgetting to add it when i rewrote my code. Thank you!
Creator of: The Reign of The Lords Era,The Gnats Franken Dungeon.
- Celtic_Minstrel
- Developer
- Posts: 2274
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: The Gnats Lua questions (creating an event using lua)
I was just pointing out why Wesnoth would have accepted that incorrect code without an error message.