Extracting a number from a targetname

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Extracting a number from a targetname

Post by Krane »

Me and my crazy ideas... :roll: Ok, here i go:

I have 8 triggers, w/ names tubetrig_1, tubetrig_2, etc.....tubetrig_8.

I'm using a single thread for all of them:
release_n:

$("tubetrig_" + self.number) waittill trigger
wait 0.1

$blabla moveto $wherever
etc
etc

end
It's working (thank god..), but I need to stablish a variable number...This is what I really want (try to "translate, please):
release_n:

$("tubetrig_" + self.number) waittill trigger
wait 0.1

level.tubebusy = self.number // <---- HERE...

$blabla moveto $wherever
etc
etc

end
The self.number does not apply to my variable :cry: ..So the question is: How to "get" the trigger number? I've been trying things like:

level.tubebusy = (self.targetname) - "tubetrig_"

and

level.tubebusy = $("tubetrig_" + self.number) - ("tubetrig_")

which is not working (quite obvious...)

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

Post by wacko »

self.number is fine, but u will 1st have to give the trigger a key #number
(don't forget the '#')

Code: Select all

release_n:
self nottriggerable
level.dada = self.number
wait 0.1
$scientist2 runto $("tube" + level.dada)
$scientist2 waittill movedone
$scientist2 turnto $("tubetrig_" + level.dada)
wait .5
$scientist2 anim scientist_chalkboard
wait 2
$scientist2 thread clipboard
if (level.dada <=4)
	{
	waitthread clonetube_s
	}
else
	{
	waitthread clonetube_n
	}
wait 5
self triggerable
end
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

string

Post by tltrude »

The trigger targetnames are strings and have no numeric value. But, when a trigger calls your thread, "self" refers to all the values that belong to it.

(self.number) is the "#number" value of the trigger. It is a real number (not a string) only because the key name started with "#". That is how #set and #group work as well and you will see them used a lot as "self.set" and "self.group".

Hope that helps!
Tom Trude,

Image
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Post by Krane »

Yeah, thanks :D ! I should had think on that..

Thanks
Image
Post Reply