Using arrays to avoid duplication of events
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.
- Bob_The_Mighty
- Posts: 870
- Joined: July 13th, 2006, 1:15 pm
Using arrays to avoid duplication of events
I got another one for you...
This is what I want to do: When a unit moves into a certain area, i want to check if that unit has learnt the 'tracking' skill. If so, it triggers a message telling you stuff.
There are 4 units, each of whom may or may not have the skill. Since there are numerous locations with different messages I only want to have one event per location which means that it must work for all 4 players.
At the start of the scenario I make sure none of them has it with this:
Then when they learn the skill I store the unit and do this:
And when I want to use the skill I have this:
But it doesn't work. I tried replacing the first four [set_variable] tags with a single one, like this:
But I'm pretty sure that doesn't work either. Do I need to store each of the units in turn to make it work? Or what?
This is what I want to do: When a unit moves into a certain area, i want to check if that unit has learnt the 'tracking' skill. If so, it triggers a message telling you stuff.
There are 4 units, each of whom may or may not have the skill. Since there are numerous locations with different messages I only want to have one event per location which means that it must work for all 4 players.
At the start of the scenario I make sure none of them has it with this:
Code: Select all
[set_variable]
name=tracking1
value=no
[/set_variable]
[set_variable]
name=tracking2
value=no
[/set_variable]
[set_variable]
name=tracking3
value=no
[/set_variable]
[set_variable]
name=tracking4
value=no
[/set_variable]
Code: Select all
[set_variable]
name=tracking[$unit.side]
value=yes
[/set_variable]
Code: Select all
[event]
name=moveto
first_time_only=no
[filter]
x=93-98
y=25-28
side="1,2,3,4"
canrecruit=1
[/filter]
[store_unit]
[filter]
x=$x1
y=$y1
[/filter]
variable=unit
[/store_unit]
[if]
[variable]
name=tracking[$unit.side]
equals=yes
[/variable]
[then]
[message]
speaker=unit
message= _ "There are deep footprints here of a very large two-legged creature. They seem to be leading north."
[/message]
[/then]
[/if]
[unstore_unit]
variable=unit
[/unstore_unit]
[/event]
But it doesn't work. I tried replacing the first four [set_variable] tags with a single one, like this:
Code: Select all
[set_variable]
name=tracking[$unit.side]
value=no
[/set_variable]
My current projects:
MP pirate campaign: The Altaz Mariners
RPG sequel: Return to Trent
MP stealth campaign: Den of Thieves
MP pirate campaign: The Altaz Mariners
RPG sequel: Return to Trent
MP stealth campaign: Den of Thieves
Re: Using arrays to avoid duplication of events
Well, there are numerous ways to do this; and there are numerous problems with the way you tried to do it.
But let's say I did want to initialize these values, and for some reason I wanted them to be in an array tracking[]. Then I would put this inside the scenario tag somewhere:
And then the variable for each side is
tracking[$side_number].is_tracking
And the value is
$tracking[$side_number].is_tracking
But, there are easier ways of doing it.
First of all, those aren't arrays. You don't really need to use arrays in this situation if you don't want to. If you play your cards right, you don't even need to initialize anything either.At the start of the scenario I make sure none of them has it with this:
Code: Select all
[set_variable] name=tracking1 value=no [/set_variable] [set_variable] name=tracking2 value=no [/set_variable] [set_variable] name=tracking3 value=no [/set_variable] [set_variable] name=tracking4 value=no [/set_variable]
But let's say I did want to initialize these values, and for some reason I wanted them to be in an array tracking[]. Then I would put this inside the scenario tag somewhere:
Code: Select all
[variables]
[tracking]
# player 0, unused
[/tracking]
[tracking]
# player 1
is_tracking=false
[/tracking]
[tracking]
# player 2
is_tracking=false
[/tracking]
[tracking]
# player 3
is_tracking=false
[/tracking]
[tracking]
# player 4
is_tracking=false
[/tracking]
[/variables]
tracking[$side_number].is_tracking
And the value is
$tracking[$side_number].is_tracking
But, there are easier ways of doing it.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
- Bob_The_Mighty
- Posts: 870
- Joined: July 13th, 2006, 1:15 pm
Quote:
And then the variable for each side is
tracking[$side_number].is_tracking
And the value is
$tracking[$side_number].is_tracking
Is that what you meant? Because I would take it to mean that you could check if they had the skill by doing this:
But that is a tautology. And anyway, how would I give them the skill? Like this?
The reason i did it like this was because I want to use it for other things. For instance, say the unit had to have tracking level 3 to get the message. Would I initialise it to zero then check like this?
Oh, I just realised I am terribly confused...
And then the variable for each side is
tracking[$side_number].is_tracking
And the value is
$tracking[$side_number].is_tracking
Is that what you meant? Because I would take it to mean that you could check if they had the skill by doing this:
Code: Select all
[if]
[variable]
name=tracking[$side_number].is_tracking
equals=$tracking[$side_number].is_tracking
[/variable]
[then]
Code: Select all
[variables]
[tracking]
tracking[$side_number].is_tracking=true
[/tracking]
[/variables]
Code: Select all
[if]
[variable]
name=tracking[$side_number].is_tracking
greater_than_equal_to=3
[/variable]
[then]
Last edited by Bob_The_Mighty on February 21st, 2007, 7:27 pm, edited 2 times in total.
My current projects:
MP pirate campaign: The Altaz Mariners
RPG sequel: Return to Trent
MP stealth campaign: Den of Thieves
MP pirate campaign: The Altaz Mariners
RPG sequel: Return to Trent
MP stealth campaign: Den of Thieves
To anwer your questions: no, no, and no. You could check if they had the skill by doing this:
The [variables] tag can only be used for initialization at the beginning of the scenario. Inside an event, you can give them the skill like this:
If you want a number instead of a boolean, you should initialize level=0 instead of is_tracking=false.
(note: in the above code I assume that $side_number variable has been set by the side turn event. Otherwise, you could use the $side of a stored unit.)
Code: Select all
[if]
[variable]
name=tracking[$side_number].is_tracking
equals=true
[/variable]
[then]
Code: Select all
{VARIABLE tracking[$side_number].is_tracking true}
(note: in the above code I assume that $side_number variable has been set by the side turn event. Otherwise, you could use the $side of a stored unit.)
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."