for (local.a=1;local.a<=35;local.a++) probllem...

Post your scripting questions / solutions here

Moderator: Moderators

Aprop
Major
Posts: 291
Joined: Mon Nov 17, 2008 3:40 pm

for (local.a=1;local.a<=35;local.a++) probllem...

Post by Aprop »

Hello

why it:

Code: Select all

	for (local.a=1;local.a<=35;local.a++)
	{
		self.target[local.a] = NULL
	}
dont work?
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

What exactly dont work, if I may ask?
Image
Aprop
Major
Posts: 291
Joined: Mon Nov 17, 2008 3:40 pm

Post by Aprop »

MOHAA cant reconize

Code: Select all

 self.target[local.a]
BEFORE

Code: Select all

=
error is:

Code: Select all

bad lvalue

I also tried

Code: Select all

$(self + ".target" + local.a) = 
but it dont work too...... idk why, this "$(self + ".target" + local.a) " work AFTER =, but before - not!
$oldier Of Ra
Lieutenant Colonel
Posts: 404
Joined: Sun Oct 16, 2005 7:16 pm
Location: Belgium
Contact:

Post 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 [ ]. :wink:
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.
Our official website: http://www.mohaairborne.co.cc
(Still accessible through http://mohaaclantb.tk and http://users.skynet.be/mohaaclantb/)

For all your bot needs!!!!

$oldier Of Ra.
Aprop
Major
Posts: 291
Joined: Mon Nov 17, 2008 3:40 pm

Post 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 [ ]. :wink:
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...
$oldier Of Ra
Lieutenant Colonel
Posts: 404
Joined: Sun Oct 16, 2005 7:16 pm
Location: Belgium
Contact:

Post by $oldier Of Ra »

Ah, .target1 isn't an array :wink:

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 :)
Our official website: http://www.mohaairborne.co.cc
(Still accessible through http://mohaaclantb.tk and http://users.skynet.be/mohaaclantb/)

For all your bot needs!!!!

$oldier Of Ra.
Aprop
Major
Posts: 291
Joined: Mon Nov 17, 2008 3:40 pm

Post by Aprop »

$oldier Of Ra wrote:Ah, .target1 isn't an array :wink:

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.
$oldier Of Ra
Lieutenant Colonel
Posts: 404
Joined: Sun Oct 16, 2005 7:16 pm
Location: Belgium
Contact:

Post 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? :)
Our official website: http://www.mohaairborne.co.cc
(Still accessible through http://mohaaclantb.tk and http://users.skynet.be/mohaaclantb/)

For all your bot needs!!!!

$oldier Of Ra.
Aprop
Major
Posts: 291
Joined: Mon Nov 17, 2008 3:40 pm

Post 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 !!
=)
$oldier Of Ra
Lieutenant Colonel
Posts: 404
Joined: Sun Oct 16, 2005 7:16 pm
Location: Belgium
Contact:

Post 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.
Our official website: http://www.mohaairborne.co.cc
(Still accessible through http://mohaaclantb.tk and http://users.skynet.be/mohaaclantb/)

For all your bot needs!!!!

$oldier Of Ra.
Aprop
Major
Posts: 291
Joined: Mon Nov 17, 2008 3:40 pm

Post by Aprop »

So how can i name it .target1, .target2 etc?
$oldier Of Ra
Lieutenant Colonel
Posts: 404
Joined: Sun Oct 16, 2005 7:16 pm
Location: Belgium
Contact:

Post 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 ;)
Our official website: http://www.mohaairborne.co.cc
(Still accessible through http://mohaaclantb.tk and http://users.skynet.be/mohaaclantb/)

For all your bot needs!!!!

$oldier Of Ra.
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post 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'.
Image
$oldier Of Ra
Lieutenant Colonel
Posts: 404
Joined: Sun Oct 16, 2005 7:16 pm
Location: Belgium
Contact:

Post by $oldier Of Ra »

I haven't really thought about that, jv :D

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
}
Our official website: http://www.mohaairborne.co.cc
(Still accessible through http://mohaaclantb.tk and http://users.skynet.be/mohaaclantb/)

For all your bot needs!!!!

$oldier Of Ra.
Aprop
Major
Posts: 291
Joined: Mon Nov 17, 2008 3:40 pm

Post by Aprop »

Thanks, but i already fixed preoblem another way... but, can i replace self.mytarget.size to 35 ?
Post Reply