Need help from experiensed coders.
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.
Need help from experiensed coders.
I try to make single-player RPG-campaign, and fase problem with [if] [variable] tags.
sample function:
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.
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]
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.
- Ken_Oh
- Moderator Emeritus
- Posts: 2178
- Joined: February 6th, 2006, 4:03 am
- Location: Baltimore, Maryland, USA
Re: Need help from experiensed coders.
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.
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.
Re: Need help from experiensed coders.
I edit first message just now.
- Ken_Oh
- Moderator Emeritus
- Posts: 2178
- Joined: February 6th, 2006, 4:03 am
- Location: Baltimore, Maryland, USA
Re: Need help from experiensed coders.
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.
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.
Re: Need help from experiensed coders.
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.)
Edit:
Thanks for "100% sure". When debugging, i'll just "buy" this potions and forgot about change variable.)
Re: Need help from experiensed coders.
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:
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?
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[3].foo" exists now in PC's memory?
Does variable "sample[2]" can be equal to something now?
- Ken_Oh
- Moderator Emeritus
- Posts: 2178
- Joined: February 6th, 2006, 4:03 am
- Location: Baltimore, Maryland, USA
Re: Need help from experiensed coders.
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.
-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.
Re: Need help from experiensed coders.
Thanks for reply and for this little tip.
Variable output.
Is there any way to display content of variable, inc(dec)remented by 1? Some markup quote or anything...
I know what I canBut it looks ugly.
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}
Re: Need help from experiensed coders.
Code: Select all
{VARIABLE foo 0}
#some other code here
[message]
speaker=narrator
message=_"$($foo + 1)"
[/message]
Re: Need help from experiensed coders.
Thanks for reply.
And one more question.
I'v got errorVariables 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.
And one more question.
I'v got error
When I use20100921 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]
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}
And I don't understand what is wrong here.
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Need help from experiensed coders.
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.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
- Elvish_Hunter
- Posts: 1576
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Need help from experiensed coders.
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)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Re: Need help from experiensed coders.
@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?".
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?".
Re: Need help from experiensed coders.
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.
What events are "other" here?http://wiki.wesnoth.org/PersistenceWML wrote:WARNING: in multiplayer, do not use persistent variables in prestart, start, and other non-synchronized events.