Need help from experiensed coders.

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.
User avatar
Xudo
Posts: 563
Joined: April 3rd, 2009, 5:26 pm

Need help from experiensed coders.

Post by Xudo »

I try to make single-player RPG-campaign, and fase problem with [if] [variable] tags.
sample function:

Code: Select all

[event]
	name=attack_end
	first_time_only=no
	[filter]
		side=1
		type=$unit
	[/filter]
	[message]
		speaker=narrator
		message= _ "Hmm."
		[option]
			message= _ "Drink healing potion."
			[command]
				[if]
					[variable]
						name=num_heal
						greater_than=0
					[/variable]
					[then]
						{ITM_POT_HEAL}
						[set_variable]
							name=num_heal
							add=-1
						[/set_variable]
					[/then]
					[else]
						[message]
							speaker=unit
							message= _ "Don't have healing potions."
						[/message]
					[/else]
				[/if]
			[/command]
		[/option]
		[option]
			message= _ "Do not drink."
		[/option]
	[/message]
[/event]
After fight game show message "hmm." with options, but
then i use "drink" with 2 healing potions game show message "Don't have healing potions."
P.S. {ITM_POT_HEAL} is the "healing potion" it's work when i place it on the ground. "num_heal" is number of healing potions.
Last edited by Xudo on May 17th, 2011, 2:42 pm, edited 2 times in total.
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Re: Need help from experiensed coders.

Post by Ken_Oh »

OK, so what's the problem exactly?

Nevermind, I see something wrong.

For: type=$unit in your filter, unit is not a type. It's not a variable but a container. You don't even want to use that as it doesn't make sense. Maybe you want to actually specify which unit type?

Unless you're already setting $unit earlier, which won't work because $unit becomes a container and is filled once the event fires.
Last edited by Ken_Oh on April 3rd, 2009, 6:15 pm, edited 1 time in total.
User avatar
Xudo
Posts: 563
Joined: April 3rd, 2009, 5:26 pm

Re: Need help from experiensed coders.

Post by Xudo »

I edit first message just now.
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Re: Need help from experiensed coders.

Post by Ken_Oh »

That part looks OK to me (and if it's firing, then I guess you can ignore what I said before).

Are you 100% sure it num_heal = 2? I would inject {DEBUG_MSG "$num_heal = number of potions"} into it just below [command] to make sure.
User avatar
Xudo
Posts: 563
Joined: April 3rd, 2009, 5:26 pm

Re: Need help from experiensed coders.

Post by Xudo »

In original there is custom unit type "RPG-hero".

Edit:
Thanks for "100% sure". When debugging, i'll just "buy" this potions and forgot about change variable.)
User avatar
Xudo
Posts: 563
Joined: April 3rd, 2009, 5:26 pm

Re: Need help from experiensed coders.

Post by Xudo »

Hi all, it's me again. =)
I have troubled with deep undertstanding of arrays in WML.

For example, we have array "sample[3]".
And do this:

Code: Select all

[set_variable]
 name=sample[2].foo
 value=1
[/set_variable]
Does variable named "sample[1].foo" exists now in PC's memory?
Does variable named "sample[3].foo" exists now in PC's memory?
Does variable "sample[2]" can be equal to something now?
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Re: Need help from experiensed coders.

Post by Ken_Oh »

Does variable named "sample[1].foo" exists now in PC's memory?
-No. sample[1] exists, (as does sample[0]) but it's an empty container.

Does variable named "sample[3].foo" exists now in PC's memory?
-Nope. Creating 2 means that 0, 1 and 2 exist.

Does variable "sample[2]" can be equal to something now?[/quote]
-No, that's just referring to a container. It has no string or numerical value.

You should really try putting this into WML in a simple scenario (I use the Tutorial scenario when I do these kinds of tests). Then go to Preferences and set Compressed Saves to off, and then make a safe file after your code as executed. It wasn't until I started breaking open save files that I really started to understand WML.
User avatar
Xudo
Posts: 563
Joined: April 3rd, 2009, 5:26 pm

Re: Need help from experiensed coders.

Post by Xudo »

Thanks for reply and for this little tip.
User avatar
Xudo
Posts: 563
Joined: April 3rd, 2009, 5:26 pm

Variable output.

Post by Xudo »

Is there any way to display content of variable, inc(dec)remented by 1? Some markup quote or anything...
I know what I can

Code: Select all

{VARIABLE foo 0}
#some other code here
{VARIABLE_OP foo add 1}
[message]
 speaker=narrator
 message=_"$foo"
[/message]
{VARIABLE_OP foo sub 1}
But it looks ugly.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Need help from experiensed coders.

Post by zookeeper »

Code: Select all

{VARIABLE foo 0}
#some other code here
[message]
 speaker=narrator
 message=_"$($foo + 1)"
[/message]
User avatar
Xudo
Posts: 563
Joined: April 3rd, 2009, 5:26 pm

Re: Need help from experiensed coders.

Post by Xudo »

Thanks for reply.

And one more question.
I'v got error
20100921 21:06:47 warning engine: variable_info: using explicitly indexed container as wrong WML type, character[1].unit[0].class[0]
20100921 21:06:47 warning engine: variable_info: using explicitly indexed container as wrong WML type, character[1].unit[0].class[1]
20100921 21:06:47 warning engine: variable_info: using explicitly indexed container as wrong WML type, character[1].unit[0].class[2]
20100921 21:06:47 warning engine: variable_info: using explicitly indexed container as wrong WML type, character[1].unit[0].class[3]
20100921 21:06:47 warning engine: variable_info: using explicitly indexed container as wrong WML type, character[1].unit[0].class[4]
When I use

Code: Select all

#define SET_CLASS_STRUCTURE ARG1 CLASS STAM STR AGI SPEED INT
	{VARIABLE {ARG1}.class_name {CLASS}}
	{VARIABLE {ARG1}.class[0] {STAM}}
	{VARIABLE {ARG1}.class[1] {STR}}
	{VARIABLE {ARG1}.class[2] {AGI}}
	{VARIABLE {ARG1}.class[3] {SPEED}}
	{VARIABLE {ARG1}.class[4] {INT}}
#enddef

{SET_CLASS_STRUCTURE character[$side_number].unit[$units_total] stalwart 5 1 2 2 0}
Variables side_number and units_total was equal to 1 and 0. All code works as expected.
And I don't understand what is wrong here.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Need help from experiensed coders.

Post by Anonymissimus »

That comes if you do variable[$index] = value instead of variable[$index].key = value. Entries in arrays are (or should be considered) containers, not scalars. Sapient will tell you better. :P
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
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Need help from experiensed coders.

Post by Elvish_Hunter »

Remember also that, to see the content of a variable, you can either open the savegame in a text editor, or type :debug :inspect . Sometimes these two things really help in understanding what went wrong.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Xudo
Posts: 563
Joined: April 3rd, 2009, 5:26 pm

Re: Need help from experiensed coders.

Post by Xudo »

@Anonymissimus
Thanks
@Elvish_Hunter
Content of this variables was equal to values I expect and all this code works. Savegame don't give me answer on question "Why I should not use such variables?".
User avatar
Xudo
Posts: 563
Joined: April 3rd, 2009, 5:26 pm

Re: Need help from experiensed coders.

Post by Xudo »

Where I can find information about event synchronizing? I need this because "PersistentWML-Owerview" have unclear explanation about events in which I can use such variables.
http://wiki.wesnoth.org/PersistenceWML wrote:WARNING: in multiplayer, do not use persistent variables in prestart, start, and other non-synchronized events.
What events are "other" here?
Post Reply