Baffled again : [set_variable] consufion

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
Spannerbag
Posts: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Baffled again : [set_variable] consufion

Post by Spannerbag »

Hi all,
not having a great time with the engine at present.
I've another weird error that I am unable to track down.

I ported some more working code from another project and tweaked it to fit (I actually mostly simplified it).

I'm getting an error that crops up where - as far as I can see - it can't ... but it does :doh:

Is the engine multi-threaded?

Before and after screen dumps (full size) with explanation following
setvarbefore.png
setvar.png
Here's the relevant code (with translator unfriendly message debug code :whistle: )

MSG simply displays whatever text is inside the brackets.

First the actual calling code (these are all macros).

Code: Select all

{MSG (About to RTC_SPEND_OR_SAVE $unit.side {DIEBGOLD})}
    {RTC_SPEND_OR_SAVE $unit.side {DIEBGOLD}}
{MSG (About to remove item)}

RTC_SPEND_OR_SAVE logic: when a player collects some gold they can either spend it immediately or save it (for the next scenario).
{MSG (About to RTC_SPEND_OR_SAVE $unit.side {DIEBGOLD})} displays the correct/expected values.

Now, RTC_SPEND_OR_SAVE simply sets a couple of variables then fires [event] name=rtc_sors

Below are the last few lines of [event] name=rtc_sors and the RTC_SPEND_OR_SAVE macro as they are in the .cfg file.

Code: Select all

{MSG (About to clear variables)}
  {CLEAR_VARIABLE rtc_sors_saved_image,rtc_sors_side,rtc_sors_amount}
{MSG (Exiting rtc_sors)}
[/event]#enddef
#
# Inline code to call spend or save event
#define RTC_SPEND_OR_SAVE SIDE AMOUNT
  {VARIABLE rtc_sors_side {SIDE}}
  {VARIABLE rtc_sors_amount {AMOUNT}}
{MSG (About to fire rtc_sors)}
  [fire_event]
    name=rtc_sors
  [/fire_event]
{MSG (Exiting RTC_SPEND_OR_SAVE)}

When it (name=rtc_sors) fires everything seems to work just fine.


Now the weird bit: the MSG Exiting rtc_sors displays, I hit return and error wml: unknown conditional wml: [set_variable] appears whilst MSG is displaying Exiting RTC_SPEND_OR_SAVE.
All the engine has done is exited an [event].
-Gibber-

Can anyone enlighten me as to where I need to look to fix this?
I've purged the cache and the error is completely reproducible in :debug and :nodebug modes.

The last few lines of the log are:

Code: Select all

libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: cHRM chunk does not match sRGB
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: cHRM chunk does not match sRGB
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: cHRM chunk does not match sRGB
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: cHRM chunk does not match sRGB
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: cHRM chunk does not match sRGB
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: cHRM chunk does not match sRGB
20220411 01:24:57 error wml: unknown conditional wml: [set_variable]
I assume the libpng warnings are not relevant? There's a lot of them though...

I've been trying to sort this for way too long and it's getting early here so I'll revisit it later.
If anyone has any suggestions, I'd really appreciate them.

Cheers!
--Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2359
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Baffled again : [set_variable] consufion

Post by Lord-Knightmare »

set_variable "assigns" a value to a variable

To compare variable I think you use either {VARIABLE_CONDITIONAL VARIABLE_NAME OPERATION VALUE} or [variable].
WML Basics 101 (actually it's course 103)
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
Spannerbag
Posts: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Baffled again : [set_variable] consufion

Post by Spannerbag »

Hi,
thanks for replying.
Lord-Knightmare wrote: April 11th, 2022, 1:12 am set_variable "assigns" a value to a variable

To compare variable I think you use either {VARIABLE_CONDITIONAL VARIABLE_NAME OPERATION VALUE} or [variable].
WML Basics 101 (actually it's course 103)
Yep, I appreciate that but there is actually no executable code (that I am aware of) between the two MSG statements?
The error message appears on screen over an [/event] action.
(First MSG is immediately before [/event], second is immediately after the calling [fire_event] code.
This is why I was wondering if the engine multi-tasked at the WML level.
Hope this all makes sense.


I have two ways forward that I can think of:
a) step through the code and examine every [set_variable] and {VARIABLE}, but as none of these occur between the MSG statements I am unclear - even if I find an error - whether it will help. But I'll give it a go.

b) Revert to the clunkier (but working) method in my other project (the one I've ended up taking an extended break from while working on this - which was supposed to be a bit of light relief :roll: ). I suppose I shouldn't try and be clever...

Thanks for taking the trouble to reply, appreciated as always.

Cheers!
--Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2359
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Baffled again : [set_variable] consufion

Post by Lord-Knightmare »

a) step through the code and examine every [set_variable] and {VARIABLE}, but as none of these occur between the MSG statements I am unclear - even if I find an error - whether it will help. But I'll give it a go.
Do you have a specialised text editor? the Mass search through all files within project directory feature can save you loads of time. I think one set_variable might be inside an [if] statement so that would be what's throwing the thing.
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
gnombat
Posts: 706
Joined: June 10th, 2010, 8:49 pm

Re: Baffled again : [set_variable] consufion

Post by gnombat »

Spannerbag wrote: April 11th, 2022, 10:30 am Yep, I appreciate that but there is actually no executable code (that I am aware of) between the two MSG statements?
The error message appears on screen over an [/event] action.
(First MSG is immediately before [/event], second is immediately after the calling [fire_event] code.
This is why I was wondering if the engine multi-tasked at the WML level.
Hope this all makes sense.
I don't think it is necessarily safe to assume that the error message is going to show up on the screen precisely at the same point where the error occurs. You know that the error is occurring some time before the error message is displayed (because it couldn't travel back in time to display an error message :lol: ). But there might be some delay for whatever reason (maybe the screen needs to get refreshed first by the "Exiting rtc_sors" message before it will finally render the error message?).

I would recommend looking inside the code for the rtc_sors event to see if that might be the culprit (I think we can only see the last 4 lines in the code above?).
User avatar
Spannerbag
Posts: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Baffled again : [set_variable] consufion : update

Post by Spannerbag »

Thanks for the replies, but I'm still stuck.

First I removed the whole die event and the error went away, so far so good.
Then I reverted to the older version of the code that just adds gold to player side, that worked, no error, still so far so good.

Edit:
Should also mention that I have gone through the macro code (and entire scenario code) checking that there are no [set_variable] or {VARIABLE} statements where they shouldn't be. Didn't find any.

Then I added the modified version to allow player to spend or save and the error resurfaced (only when the player saves, if gold is added there is no error. Should have mentioned that earlier :whistle: ).

As a sanity check that the old version wasn't also executing I put a message there. It didn't display so the new version (only) is executing.

I then put a message after every statement in the new version in case the engine needed to "catch up" with itself but the error always appears when the event fired in [fire_event] ends (that is, after the final statement immediately before [/event]).

So the error appears somewhere between immediately before [/event] and after the enclosing [/fire_event] but before any statement following said [/fire_event].
This has been tested using [message].
There are no executable statements there :augh:

(To clarify:
when the first [message] immediately before [/event] is displayed there is no message on screen.
When I continue then when the next [message] displays, imediately after [/fire_event] the error is displayed).

Interestingly, all the relevant variables have the correct values.

With the tools I have I cannot get any further with this.
The logfile reports the error but that's all.

As gnombat commented the error could be late reported but it only appears when a specific path through a specific code block executes.
I cannot localise the issue any further than between two statements with no intervening executable code without (as far as I can see) getting into source code or at least heavily into lua.

I'm happy to post the whole code block here is anyone wants to look but to me the code appears OK.
(The actual problematic code is all in one file; gold_utils.cfg I renamed it from gold.cfg in case that was causing some weird problem and also renamed an event that had "event" in its name for the same reason). Didn't help :(

I'll revert to the older, messier way of doing things and see if that works.

Cheers,
--Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Spannerbag
Posts: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Baffled again : [set_variable] FIXED

Post by Spannerbag »

I was being an idiot... again :oops:

I had to have done something daft and couldn't let it go so I revisited the [if] statements (again).
There was one very simple macro I'd moved to the top of file and it worked fine (or seemed to) and I''d thought no more about it.
This was done early on, seemed reliable and tbh I'd only skimmed through it... mistake!
By a combination of circumstance even though broken the code gave the correct result in this particular instance so I assumed it was working and didn't look too much into its innards.

The error came from there and was reported, but rather late.
I'd looked at that code a few times and missed what I'd done, I guess when cutting and pasting to populate [elseif] and [else] I had indeed put an "_OP" where I should've put "_CONDITIONAL".

I think I'd spent too long on this without a break and was getting "code blind". At least that's my excuse!

As always thanks for the help and replies and I hope my thrashing around provided some entertainment at least! :)

I'm going to have a break now.

Cheers!
--Spanerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2359
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Baffled again : [set_variable] consufion

Post by Lord-Knightmare »

The error came from there and was reported, but rather late.
I'd looked at that code a few times and missed what I'd done, I guess when cutting and pasting to populate [elseif] and [else] I had indeed put an "_OP" where I should've put "_CONDITIONAL".

I think I'd spent too long on this without a break and was getting "code blind". At least that's my excuse!
XD
Told ya so that there was supposed to be a _CONDITIONAL XD

Anyways, enjoy the break. Cool movies and TV series are out now.
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Post Reply