Latest Posts

Topic: lua: if statement do not work

kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2434
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2018-01-09, 17:45

I want to check if a field has an immovable and if it has one, the loop has to break.

This example do not work:

   f = map:get_field(10,20)
    while true do
        -- do some thing
        sleep(10000)
        if f.immovable ~= nil then
            break
        end
    end

I put a print statements before the if and it shows me that f.immovable ~= nil is true if field f has an immovable. So the if should catch, but it doesn't. A working solution is this example:

    f = map:get_field(10,20)
    while true do
        -- do some thing
        sleep(10000)
        has_immovable = f.immovable
        if has_immovable ~= nil then
            break
        end
    end

What is the difference? Why does the first example do not work?

In the first example i have also tried to enclose the if-condition in braces, but this does not work also... it drives me crazy face-grin.png

Edited: 2018-01-09, 17:48

Fight simulator for Widelands:
https://wide-fighter.netlify.app/

Top Quote
SirVer

Joined: 2009-02-19, 15:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2018-01-09, 19:55

Both examples should work just fine. I am skeptical if this is indeed the full code. For example, if f is a global variable (default in lua), it could be that it is reassigned in a different cooroutine, so you are not checking what you think you are.

Can you make the full code available somewhere for investigation?


Top Quote
kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2434
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2018-01-09, 21:28

You can find a scenario map here: https://c.1und1.de/@520176427140645159/g-IjyQ6VRx2p-QeiQXSmvw

The function showing the problem is in scripting/story_script and is called wobble_field()

Thanks for looking into this issue face-smile.png


Fight simulator for Widelands:
https://wide-fighter.netlify.app/

Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2018-01-10, 13:38

kaputtnik wrote:

You can find a scenario map here: https://c.1und1.de/@520176427140645159/g-IjyQ6VRx2p-QeiQXSmvw

The function showing the problem is in scripting/story_script and is called wobble_field()

Thanks for looking into this issue face-smile.png

Perhaps the problem might be that it should read f.immovable instead of f.immmovable like in your script. face-wink.png

BTW: Really looking foraward for the scenario face-wink.png sounds funny and remembers me of something hihihihi. gngngngngn hahahahah

Edited by kaputtnik: Make this post visible

Edited: 2018-01-10, 16:29

Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2018-01-10, 13:39

Since when the comments have to be moderated?

I just sent a comment explaining the issue and used some funny strings could this be the problem?

Edited: 2018-01-10, 13:40

Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2018-01-10, 13:42

Okay then again the solution for you kaputtnik without any sense of humour.

the error might be just a typo just remove one "m" from immmovable.

Really looking forward to the scenario though

Edited: 2018-01-10, 13:47

Top Quote
kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2434
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2018-01-10, 16:29

hessenfarmer wrote:

Since when the comments have to be moderated?

Sometimes they have to ...

I just sent a comment explaining the issue and used some funny strings could this be the problem?

No, the problem was quoting my post, which triggered our spam checker to hide the post. Sorry for inconvenience face-upset.png


Fight simulator for Widelands:
https://wide-fighter.netlify.app/

Top Quote
kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2434
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2018-01-10, 16:45

hessenfarmer wrote:

the error might be just a typo just remove one "m" from immmovable.

Oh... i didn't saw that, really... and strange that no error was triggered... Many thanks for clearing this up face-smile.png I think i have to set a bigger font size in my editor...

These kind of failures could make one spend hours to find the failure, at least me face-wink.png

May i need your help with this scenario, i have some ideas but i am not sure if they could be implemented. But i see creating a scenario is a huge work, and i have big respect regarding your work on the empire 4 scenario!


Fight simulator for Widelands:
https://wide-fighter.netlify.app/

Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2018-01-10, 22:47

kaputtnik wrote:

May i need your help with this scenario, i have some ideas but i am not sure if they could be implemented. But i see creating a scenario is a huge work, and i have big respect regarding your work on the empire 4 scenario!

you are welcome If I could help I will do so, although I have already some ideas for Empire 05


Top Quote
GunChleoc
Avatar
Joined: 2013-10-07, 15:56
Posts: 3324
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2018-01-17, 14:56

The reason that this will not crash that Lua interprets f.immmovable as nil, because it doesn't exist. It would crash though if f didn't exist either.


Busy indexing nil values

Top Quote