is a targetname(number) possible?

Post your scripting questions / solutions here

Moderator: Moderators

User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

is a targetname(number) possible?

Post by wacko »

hopefully the last one for today...

i have 8 groups of script_objects doing just the same ( quite alot), so the script will get quite long. Could I give them targetnames like thing_1(1) up to thing_1(8) and use a for-loop in the script, like

Code: Select all

for(local.i;i<8;i++)
{
thing_1(local.i) dosumthin
}
would be great, also for playing around with parameters
Combat Kirby
Lance Corporal
Posts: 18
Joined: Wed Mar 03, 2004 7:50 pm

Post by Combat Kirby »

Name then, thing_1 , thing_2 , thing_3 and so on up to how many you want. Lets say you have 20 set up this way, then script them:

Code: Select all

for(local.i = 1 ; local.i <= 20 ; local.i ++)
{
   $("thing_" + local.i) do something
}
Or name them all one target name say like "thing" then code them this way:

Code: Select all

for(local.i = 1 ; local.i <= $thing.size ; local.i ++)
{
   $thing[local.i] do something
}

Hope that helps

Kirby.
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

Combat Kirby wrote:Hope that helps
Yeah! Tvm :D
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

self

Post by tltrude »

If your common thread uses "self" then all the objects can use it.

thing_1 thread common_stuff
thing_2 thread common_stuff

common_stuff:

self dowhatever

end

At least that is how I think it works.

==================================

Also, you can do an array if all the "things" have the same targetname.


for (local.i = 1 ; local.i <= $thing.size ; local.i ++)
{
$thing[local.i] thread common_stuff // or $thing[local.i] dosomethin
}

But, there is not much need for that if the things do not have different properties. Study the "door_locked.scr" in global.

====================================

If all the things do the same stuff at the same time, why not just give them all the same targetname and one thread in the script to move them?

thing_mover:

$thing dosomethin

end
Tom Trude,

Image
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

might be possible, albeit these 8 groups have to do their stuff one after the other: There are rather 1st_thing_1, 2nd_thing_1, 3rd_thing_1... , then 1st_thing_2, 2nd_thing_2, 3rd_thing_2... and so on. So handle them all with same targetname won't work and the self method seems to become rather difficult. The for loop of Kirby in my eyes is perfect (and it's already working :wink: )

tnx m8
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

you could have 2 for loops and the 1st would use the 2nd to find them all

start:
for (local.i=1; local.i<= 8; local.i++) //change 8 to number of groups if different
{
thread all_go local.i
}
end

all_go local.i:
for (local.j=1; local.j<= 5; local.j++) //change 5 to number of things in group
{
$("thing_" + local.i + local.j) do your thing
}
end
hope this helps, prob not cos it's all foreign 2 me :-/
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

Wahooo nuggets, you're still alive :D :D

but that's probably just me being rarely in the scripting forum. :oops:

2 for loops, yes, i could do so, but those 1st_things do different tasks than the 2nd_things and so on. So I'd need an if clause to give them their appropriate task, wouldn't make much sense...
And then, everything will become completely different anyway as I decided yesterday. No more loops but threads started by triggers (hi, Tom :wink:) so I'll have a completely different script structure which I probably will discuss in another thread here at map :cry:
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

lol, you're talking like you've been scripting for 10years or more :P to think only those few months ago when you were wondering how people write whole scripts for what they need

is this your new calling in life? :D
hope this helps, prob not cos it's all foreign 2 me :-/
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

if u would see my scripting you wouldn't say so :lol: . no, i still prefer mapping but what must be done must be done :wink: and for the sake of u -and lots of help from these great ppl in this forum - i'm even able to do it :D
M&M
General
Posts: 1427
Joined: Sun Sep 14, 2003 1:03 am
Location: egypt
Contact:

Post by M&M »

There are rather 1st_thing_1, 2nd_thing_1, 3rd_thing_1... , then 1st_thing_2, 2nd_thing_2, 3rd_thing_2... and so on
y not thing_1_1 thing_1_2 thing_2_1 thing_2_2 ...... u get the picture .
at least its a beat easier 2 look at and understand instead of having numbers b4 and after . or u could do it like mohradient does when u copy something witha target name .it names them t1 t2 t3 ..... .try t1_1 t1_2 ...u get the picture :idea: . :wink:
Image
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

lol: these were just example names: in fact they're called different...
M&M
General
Posts: 1427
Joined: Sun Sep 14, 2003 1:03 am
Location: egypt
Contact:

Post by M&M »

yeah i know,thats y i used them 2 give u an example of what i mean :wink: .
Image
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

okay.
but now, i need something else

to call the script objects with a trigger by a setthread, I must use in the script their names like $("thing_"+self.number). When I give the trigger a k/v:number/1, this doesn't work, self.number is NIL. How would I have to do it then? And why?
Combat Kirby
Lance Corporal
Posts: 18
Joined: Wed Mar 03, 2004 7:50 pm

Post by Combat Kirby »

When assigning keys to your entites, you must place a "$" in front of the key entry such as:

$my_value

This tells the script to use this entry as a string.
"#" are for numeric entries.

Regards,
Kirby.
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

so, I gave the triggeres e.g. a k/v:#number/1 and everythings working perfectly. tvm, Kirby :D
Post Reply