Page 1 of 1

Extracting a number from a targetname

Posted: Thu May 13, 2004 5:58 am
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!!!!

Posted: Thu May 13, 2004 8:33 am
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

string

Posted: Thu May 13, 2004 10:34 am
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!

Posted: Thu May 13, 2004 3:33 pm
by Krane
Yeah, thanks :D ! I should had think on that..

Thanks