The Gnats Lua questions (creating an event using lua)

Discussion of Lua and LuaWML support, development, and ideas.

Moderators: Forum Moderators, Developers

Re: The Gnats Lua questions (creating an event using lua)

Postby The_Gnat » May 5th, 2017, 10:30 pm

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"
What would be causing this problem?

Here is a screenshot of the error:

error.png
error.png (9.76 KiB) Viewed 772 times
User avatar
The_Gnat
 
Posts: 1266
Joined: October 10th, 2016, 3:06 am

Re: The Gnats Lua questions (creating an event using lua)

Postby Ravana » May 5th, 2017, 10:34 pm

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"

That only means it exists as wml variable, not as Lua variable.

By not using quotes, you ask variable to be evaluated.
User avatar
Ravana
Moderator
 
Posts: 1450
Joined: January 29th, 2012, 12:49 am
Location: Estonia

Re: The Gnats Lua questions (creating an event using lua)

Postby The_Gnat » May 5th, 2017, 10:43 pm

Sorry about confusion my exact code is this:

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]


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.

For simple variables I can say use quotes, for objects see reference.


I will try doing it again with quotes: local victoriousSide wesnoth.get_variable("the_killer.side")
User avatar
The_Gnat
 
Posts: 1266
Joined: October 10th, 2016, 3:06 am

Re: The Gnats Lua questions (creating an event using lua)

Postby Ravana » May 5th, 2017, 10:45 pm

Still no =
User avatar
Ravana
Moderator
 
Posts: 1450
Joined: January 29th, 2012, 12:49 am
Location: Estonia


Re: The Gnats Lua questions (creating an event using lua)

Postby The_Gnat » May 5th, 2017, 10:52 pm

Hmm... I have added an "=" but it still gives the same error...

Spoiler:
User avatar
The_Gnat
 
Posts: 1266
Joined: October 10th, 2016, 3:06 am

Re: The Gnats Lua questions (creating an event using lua)

Postby Ravana » May 5th, 2017, 10:56 pm

By not using quotes, you ask variable to be evaluated.
User avatar
Ravana
Moderator
 
Posts: 1450
Joined: January 29th, 2012, 12:49 am
Location: Estonia

Re: The Gnats Lua questions (creating an event using lua)

Postby The_Gnat » May 5th, 2017, 11:15 pm

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:

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]
User avatar
The_Gnat
 
Posts: 1266
Joined: October 10th, 2016, 3:06 am

Re: The Gnats Lua questions (creating an event using lua)

Postby Celtic_Minstrel » May 8th, 2017, 1:48 am

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.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Celtic_Minstrel
Developer
 
Posts: 754
Joined: August 3rd, 2012, 11:26 pm

Re: The Gnats Lua questions (creating an event using lua)

Postby The_Gnat » May 12th, 2017, 9:41 pm

Yes i realized i needed a "=" but for some (stupid) reason i kept forgetting to add it when i rewrote my code. Thank you! :D
User avatar
The_Gnat
 
Posts: 1266
Joined: October 10th, 2016, 3:06 am

Re: The Gnats Lua questions (creating an event using lua)

Postby Celtic_Minstrel » May 12th, 2017, 11:43 pm

I was just pointing out why Wesnoth would have accepted that incorrect code without an error message.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Celtic_Minstrel
Developer
 
Posts: 754
Joined: August 3rd, 2012, 11:26 pm

Previous

Return to Lua Labs

Who is online

Users browsing this forum: No registered users and 3 guests