## {CLEAR_VARIABLE} and [clear_variable] work in one place but

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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.
A Guy
Posts: 790
Joined: May 24th, 2008, 1:55 am

### {CLEAR_VARIABLE} and [clear_variable] work in one place but

not in another place. I can't get why {CLEAR_VARIABLE} just REFUSES to clear the variable. Is there any other way I can delete a variable?

Here's where it works.

Code: Select all

#define MW_CLEAR_SPELL SIDE NAME
{VARIABLE spell_cleared no}
{FOREACH {SIDE}|.spells.option i}
[if]
{MW_VARIABLE {SIDE}|.spells.option[$i].name equals {NAME}} [then] [if] {MW_VARIABLE spell_cleared not_equals yes} [then] {CLEAR_VARIABLE {SIDE}|.spells.option[$i]}
{VARIABLE spell_cleared yes}
[/then]
[/if]
[/then]
[/if]
{NEXT i}
{CLEAR_VARIABLE spell_cleared}
#enddef
Here's where it doesn't work.

Code: Select all

#define MW_DESTROY_SPELL SIDE NAME
{VARIABLE spell_destroyed no}
{FOREACH {SIDE}|.discarded_spells.option z}
[if]
{MW_VARIABLE {SIDE}|.discarded_spells.option[$z].name equals {NAME}} [then] [if] {MW_VARIABLE spell_destroyed not_equals yes} [then] {CLEAR_VARIABLE {SIDE}|.discarded_spells.option[$z]}
{VARIABLE spell_destroyed yes}
[/then]
[/if]
[/then]
[/if]
{NEXT z}
{CLEAR_VARIABLE spell_destroyed}
#enddef
Use of {DEBUG_MSG} and :inspect confirm that I'm using all the right variable names, and everything but {CLEAR_VARIABLE} or [clear_variable] is working there.
I'm just... a guy...
I'm back for now, I might get started on some work again.

Pentarctagon
Forum Administrator
Posts: 4245
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

### Re: {CLEAR_VARIABLE} and [clear_variable] work in one place

So if the spell_destroyed variable is set to yes and you output the value of ${SIDE}|.discarded_spells.option[$z].name immediately before it is cleared and immediately after, it shows the exact same value?
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

### Re: {CLEAR_VARIABLE} and [clear_variable] work in one place

It might help if we knew what was the value of {SIDE} when this was called, and which clear_variable isn't working.

Another question: have you tried checking the error log? I would turn the engine log to the info level.

--log-info=engine
(or similar command)

since so much is handled in lua now it might be prudent to use this instead:

--log-info=engine,scripting/lua,wml
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."

A Guy
Posts: 790
Joined: May 24th, 2008, 1:55 am

### Re: {CLEAR_VARIABLE} and [clear_variable] work in one place

Pentarctagon wrote:So if the spell_destroyed variable is set to yes and you output the value of ${SIDE}|.discarded_spells.option[$z].name immediately before it is cleared and immediately after, it shows the exact same value?
That is correct.
Sapient wrote:It might help if we knew what was the value of {SIDE} when this was called, and which clear_variable isn't working.
{SIDE} = $side_number, the second code isn't working. Another question: have you tried checking the error log? I would turn the engine log to the info level. --log-info=engine (or similar command) since so much is handled in lua now it might be prudent to use this instead: --log-info=engine,scripting/lua,wml Not sure how to do that. I'm just... a guy... I'm back for now, I might get started on some work again. SlowThinker Posts: 876 Joined: November 28th, 2008, 6:18 pm ### Re: {CLEAR_VARIABLE} and [clear_variable] work in one place Did you check what exactly you were clearing? Code: Select all {VARIABLE aux {SIDE}|.discarded_spells.option[$z]}
[inspect]
name=$aux [/inspect] {CLEAR_VARIABLE$aux}
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums

Anonymissimus
Inactive Developer
Posts: 2460
Joined: August 15th, 2008, 8:46 pm
Location: Germany

### Re: {CLEAR_VARIABLE} and [clear_variable] work in one place

A Guy wrote:
Another question: have you tried checking the error log? I would turn the engine log to the info level.

--log-info=engine
(or similar command)

since so much is handled in lua now it might be prudent to use this instead:

--log-info=engine,scripting/lua,wml

Not sure how to do that.
Make a link to wesnoth.exe with execution directory the wesnoth.exe's dir and command "C:\path\to\wesnoth.exe -log-debug=engine"

There are hardly any corresponding log message calls in the lua or the lua-related C++ code, so passing scripting/lua generally is only helpful if one puts such a message there oneself.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign

JaMiT
Developer
Posts: 511
Joined: January 22nd, 2012, 12:38 am

### Re: {CLEAR_VARIABLE} and [clear_variable] work in one place

A Guy wrote:
Sapient wrote:It might help if we knew what was the value of {SIDE} when this was called, and which clear_variable isn't working.
{SIDE} = \$side_number, the second code isn't working.
It might help to know which CLEAR_VARIABLE in the second code block isn't working (clearing a discarded spell or clearing spell_destroyed).

In any event, it works for me. I put the following (basically your two macros with feedback [message]s added, a definition for MW_VARIABLE, plus an event) into a test scenario:
CLEAR_VARIABLE test
When I ran the scenario, I got the feedback

Code: Select all

Pre-clear spell (1): kill
Post-clear spell (1):
Pre-clear discarded spell (0): test
Post-clear discarded spell (0): kill
In addition, using :inspect to look at the variables after the event showed that the two arrays were each down to one element, and that the flag variables were no longer defined. So it all looks to be working, regardless of which CLEAR_VARIABLE you meant.

A Guy
Posts: 790
Joined: May 24th, 2008, 1:55 am

### Re: {CLEAR_VARIABLE} and [clear_variable] work in one place

Okay, I fixed the problem by changing the place the spell-destroying macro was called. So it wasn't the code, it was its location. Thanks guys.
I'm just... a guy...
I'm back for now, I might get started on some work again.