Question on [if] events.

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
Sire
Posts: 164
Joined: April 6th, 2012, 11:03 pm
Location: USA

Question on [if] events.

Post by Sire »

I managed to finish my interlude scenario for Red Winter Reborn, however one important aspect is bugged and I can't figure out why.

I'm trying to make sure the main event fires as long as the variable doesn't equal 0. However, as it is currently set up, it will fire the [then] value even if the value is 0.
-- Now, there may be something embeded into the save file itself as I'm loading an existing "save game" that loads the scenario's start (an easy way to skip to a certain scenario to check new code), but I'm not sure if that has anything to do with global variables.
-- Trying to use the greater_than tag instead resulted in the event firing the [else] version regardless of the value.
== I know the menu works as the .cfg file changes depending on the selection, it's just the conditionals of the event that has me confused.

Any assistance on this would be appreciated!

Code: Select all

   [get_global_variable]
	namespace=Red_Winter_Reborn
	from_global==vWorkshop
	to_local=vWorkshop
	side=1
   [/get_global_variable]

* * * PLACE OTHER SCENARIO CODE HERE * * *

	[fire_event]
	name=workshoptime	# This mainly revolves around the Abandoned Workshop secret in Chapter Two. If it is obtained, a sequence plays.
	[/fire_event]		#   Otherwise, there's a small dialogue hinting at its existance, and the sequence is skipped.

* * * PLACE OTHER SCENARIO CODE HERE * * *

	[event]
	name=workshoptime

	[if]
    [variable]
       name=vWorkshop
       not_equals=0	# 0 is the value for the secret not being found (or restarting scenario 2 and not finding it). If the player already made a selection, they could come back here to change their mind before scenario four.
    [/variable]	
		[then]

* * * INSERT DIALOGUE AND MUSIC * * *

	[message]
	speaker=Aldras	
	message= _ "Oh, and by the way, I'll have to let the lads know about bringing the item you want. You should get it the next time you return to Estlyn.

(As a reward for finding the Abandoned Workshop secret in Scenario Two, you get to choose a unique item for one of the Council Members. However, the item will not be ready until you return to Estlyn, so please keep this in mind!)"
		[option]
		image="attacks/hammer-dwarven-runic.png"
		message= _ "[Mycen] Thunder Hammer
-- Melee Attacks +1 Damage
-- Gain a Magical Ranged Attack
"
		[command]
		{VARIABLE vWorkshop 1}	# Number Order: 1 Mycen, 2 Syris, 3 Tudok, 4 Lann, 5 Vanrir, 6 Denvan, 7 Aldras, 8 Aleria
			[message]
			speaker=Mycen
			message = _ "I think I'll take the Thunder Hammer."
			[/message]

			[message]
			speaker=Aldras
			message = _ "Ready to call down the thunder, eh? I'll send word for it."
			[/message]
		[/command]
		[/option]

* * * INSERT OTHER MENU ITEMS * * *

		[option]
		image="icons/scroll_red.png"
		message= _ "No Trade
-- (No benefit and acts as if you never found the secret.)
"
		[command]
		{VARIABLE vWorkshop 0}
			[message]
			speaker=Mycen
			message = _ "Sorry Aldras, but I think we will hold onto the blueprints and ore. There will be no trade today."
			[/message]

			[message]
			speaker=Aldras
			message = _ "A shame, but understandable. I just hope you know what you are doing with all that knowledge."
			[/message]
		[/command]
		[/option]
	[/message]

	[set_global_variable]
	namespace=Red_Winter_Reborn
	from_local=vWorkshop
	to_global=vWorkshop
	side=1
	immediate=no
	[/set_global_variable]

	[message]
	speaker=Aldras
	message = _ "Well, I think that wraps up everything on my end. Anyone else have something to say?"
	[/message]
		[/then]

	[else]
		[message]
		speaker=Aldras
		message = _ "I suppose not. It's just a shame we didn't find anything of value inside those Dwarven Ruins. Perhaps if we had more time..."
		[/message]	
	[/else]
	[/if]
	[/event]
Current Projects: [Sire's Scenarios] || [Red Winter Reborn]
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Question on [if] events.

Post by Helmet »

Sire wrote: December 10th, 2022, 1:49 am Any assistance on this would be appreciated!
Maybe you could try numerical_not_equals?
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
Sire
Posts: 164
Joined: April 6th, 2012, 11:03 pm
Location: USA

Re: Question on [if] events.

Post by Sire »

Helmet wrote: December 10th, 2022, 3:35 am
Sire wrote: December 10th, 2022, 1:49 am Any assistance on this would be appreciated!
Maybe you could try numerical_not_equals?
Afraid that doesn't work. Doing this just forces the [else] command to be done, even if the persist is a 1 or a 0.
-- Even changing the placeholder variable value at the start of the scenario does nothing,
-- I even tried to check the global variable in its own separate event (get global variable), but that seems to do nothing.
== Same thing happens if I try greater_than=0. It just forces the [else] command.

It's either the way I have everything set up, or the conditions are just not working right for some reason.
-- It's also a bit weird as I could've swore I had global variables work in the original version of Red Winter, as well as variables working in an [if] tag with the original Alchemist Shop...
== Looking at the original, I used a [filter_condition] tag. Maybe it has something to do with the [if] tag or the way I have it set up with [variable]?

* * * EDIT * * *

Just booted up the original Red Winter and everything still seems to work, so I'm still at a loss on what's going on with the Reborn variant.
-- The Immortal Code works (killed Council will "revive" at the start of the next scenario), the secret Workshop works (the "tank" spawns in at scenario 5 if unlocked, otherwise it doesn't), and even the Alchemist Shop keeps up with the current gold which can easily change throughout the scenario.
== Granted, that code used [filter_condition] tags for its events, which is a little different. The Alch Shop is in the realm of using [if], but uses local variables instead of global.

Tring to experiment some more, even trying to do something like equals_to=1 forces a certain outcome, even despite changing persist and local variables.
-- Again, it is entirely possible that something may be baked into the save file as I'm using that for testing instead of manually going through each scenario. Just tested it by doing a quick debug run-through, one time not getting the secret and the next obtaining it. The persist file did update, however the outcome was the same regardless of its value.
-- I'm just running into a brick wall at this point. If anyone wants to look at the actual scenario file, I attached it to this post.
-- EDIT 2: gnombat found the issue, it was a double = sign for reading in the global variable. A single letter off throws the whole code in disarray, gotta love it...
Last edited by Sire on December 10th, 2022, 6:33 am, edited 2 times in total.
Current Projects: [Sire's Scenarios] || [Red Winter Reborn]
gnombat
Posts: 704
Joined: June 10th, 2010, 8:49 pm

Re: Question on [if] events.

Post by gnombat »

I don't really know much about persistent variables, but surely this line should not have two equals characters?

Code: Select all

from_global==vWorkshop
User avatar
Sire
Posts: 164
Joined: April 6th, 2012, 11:03 pm
Location: USA

Re: Question on [if] events.

Post by Sire »

gnombat wrote: December 10th, 2022, 6:08 am I don't really know much about persistent variables, but surely this line should not have two equals characters?

Code: Select all

from_global==vWorkshop
...That'll do it. That single error was driving me nuts and was the reason why it wasn't working properly.

Thanks for finding it!
Current Projects: [Sire's Scenarios] || [Red Winter Reborn]
Post Reply