Page 1 of 2
for (local.a=1;local.a<=35;local.a++) probllem...
Posted: Tue Dec 02, 2008 8:11 am
by Aprop
Hello
why it:
Code: Select all
for (local.a=1;local.a<=35;local.a++)
{
self.target[local.a] = NULL
}
dont work?
Posted: Tue Dec 02, 2008 2:50 pm
by jv_map
What exactly dont work, if I may ask?
Posted: Tue Dec 02, 2008 7:02 pm
by Aprop
MOHAA cant reconize
BEFORE
error is:
I also tried
but it dont work too...... idk why, this "$(self + ".target" + local.a) " work AFTER =, but before - not!
Posted: Tue Dec 02, 2008 8:05 pm
by $oldier Of Ra
$(self + ".target" + local.a)
Self is not a targetname, self is a predefined object. And local.a is a variable which (in this case) needs to be used in an array, so it needs to be between [ ].
This will not work. You must use self.target[local.a] like in your first post.
Make sure self exists and I think you need to use NIL instead of NULL.
Posted: Tue Dec 02, 2008 9:00 pm
by Aprop
$oldier Of Ra wrote:$(self + ".target" + local.a)
Self is not a targetname, self is a predefined object. And local.a is a variable which (in this case) needs to be used in an array, so it needs to be between [ ].
This will not work. You must use self.target[local.a] like in your first post.
My bad, i mean self.targetanme .... nvm, BUT self.target[local.a] dont worked too... but i fix'd the problem another way..
self exist, because self.target1 = worked...
Posted: Wed Dec 03, 2008 12:24 pm
by $oldier Of Ra
Ah, .target1 isn't an array
The easiest way would be to make turn your sum of targets (eg .target1, .target2, .target3...) into an array (eg .target[1], .target[2]...) When you do that, your script (in your first post) will work.
Then you can make your script even more dynamic, you can replace that 35 integer by self.target.size

Posted: Wed Dec 03, 2008 12:42 pm
by Aprop
$oldier Of Ra wrote:Ah, .target1 isn't an array
The easiest way would be to make turn your sum of targets (eg .target1, .target2, .target3...) into an array (eg .target[1], .target[2]...) When you do that, your script (in your first post) will work.
Then you can make your script even more dynamic, you can replace that 35 integer by self.target.size

Huh? I didnt understand it at all, but i fixed my problem yesterday using a laaaaaaaaaaarge switch.
Posted: Wed Dec 03, 2008 3:02 pm
by $oldier Of Ra
When you use .target1, you give the player the variable .target1.
But if you give the player .target[1], you give the player the .target variable's first entry, then .target[2] is the second entry etc...
This is called an array, the player only gets 1 variable (= .target) but that variable contains a whole set of values.
Only when using an array, you can track down all targets with just 1 for statement instead of a huge switch statement.
For example this:
Code: Select all
for (local.i = 1; local.i <= $player.size; local.i++)
{
$player[local.i] iprint "hello"
}
There's only 1 targetname and that's $player. But that targetname can refer to all entities using the same targetname. Each time a player enters a server, 1 $player will be added.
$player is an array, meaning $player[1] will be the first player who entered the server, $player[2] the second and so on... When a new player joins the server, he will be added to the array (+1).
There is no $player1, $player2... Only $player[1] and $player[2]... this is probably what confused you when you made that first post.
Do you understand?

Posted: Wed Dec 03, 2008 6:52 pm
by Aprop
$oldier Of Ra wrote:
There is no $player1, $player2... Only $player[1] and $player[2]... this is probably what confused you when you made that first post.
I know...
but im talking about this:
Code: Select all
for (local.a=1;local.a<=35;local.a++)
{
self.target[local.a] = NULL
}
and i WANT get self.target1 self.target2 self.target3 self.target4 .... self.target35.. do you understand? This entity (self here) havent ANY target, it have only target1- target35
and self != $player !!
=)
Posted: Wed Dec 03, 2008 7:29 pm
by $oldier Of Ra
Look, that was an example, totally not related with your script. I was just trying to explain what an array was.
Like I said before if you want that script of yours to work don't name it .target1, .target2 etc, but name it .target[1] and .target[2].
Because this:
Code: Select all
for (local.a=1;local.a<=35;local.a++)
{
self.target[local.a] = NULL
}
seeks an array and
not a series of variables.
Posted: Wed Dec 03, 2008 8:52 pm
by Aprop
So how can i name it .target1, .target2 etc?
Posted: Wed Dec 03, 2008 9:39 pm
by $oldier Of Ra
I don't think it is possible to track .target1, .target2 etc with a for statement...
Name them .target[1], .target[2], .target[3] etc. If you name all 35 like this, then your script will work

Posted: Thu Dec 04, 2008 11:43 am
by jv_map
Yup, $oldier shows some good understanding here
There is a more subtle problem though, (for entities) 'target' is a reserved field which is also initialized to an empty string (""). That is, if you write self.target[5] you'd be trying to access the 6th character in the string. Since the empty string has no characters (length 0), your code fails with the 'bad lvalue' warning: there is no character for any index.
The problem is circumvented by using a different name (identifier) for your array, for example 'self.targets'.
Posted: Thu Dec 04, 2008 1:07 pm
by $oldier Of Ra
I haven't really thought about that, jv
So then the solution for Aprop would be this:
self.mytarget[1] = $entity1
self.mytarget[2] = $entity2
self.mytarget[3] = $entity3
self.mytarget[4] = $entity4
and so on
for (local.i = 1; local.i <= self.mytarget.size; local.i++)
{
self.mytarget[local.i] = NULL //or NILL
}
Posted: Thu Dec 04, 2008 1:18 pm
by Aprop
Thanks, but i already fixed preoblem another way... but, can i replace self.mytarget.size to 35 ?