Page 1 of 2
is a targetname(number) possible?
Posted: Fri Mar 26, 2004 11:02 pm
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
Posted: Fri Mar 26, 2004 11:41 pm
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.
Posted: Fri Mar 26, 2004 11:58 pm
by wacko
Combat Kirby wrote:Hope that helps
Yeah! Tvm

self
Posted: Sat Mar 27, 2004 3:31 am
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
Posted: Sat Mar 27, 2004 6:22 am
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

)
tnx m8
Posted: Sat Mar 27, 2004 4:38 pm
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
Posted: Sat Mar 27, 2004 6:35 pm
by wacko
Wahooo nuggets, you're still alive
but that's probably just me being rarely in the scripting forum.
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

) so I'll have a completely different script structure which I probably will discuss in another thread here at map

Posted: Sat Mar 27, 2004 6:53 pm
by nuggets
lol, you're talking like you've been scripting for 10years or more

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?

Posted: Sat Mar 27, 2004 9:26 pm
by wacko
if u would see my scripting you wouldn't say so

. no, i still prefer mapping but what must be done must be done

and for the sake of u -and lots of help from these great ppl in this forum - i'm even able to do it

Posted: Sat Mar 27, 2004 10:08 pm
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

.

Posted: Sat Mar 27, 2004 11:16 pm
by wacko
lol: these were just example names: in fact they're called different...
Posted: Sat Mar 27, 2004 11:36 pm
by M&M
yeah i know,thats y i used them 2 give u an example of what i mean

.
Posted: Sun Mar 28, 2004 12:10 am
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?
Posted: Sun Mar 28, 2004 3:14 am
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.
Posted: Sun Mar 28, 2004 11:17 am
by wacko
so, I gave the triggeres e.g. a k/v:#number/1 and everythings working perfectly. tvm, Kirby
