Game Development Community

Adding a behavior

by Martyn · in Torque Game Builder · 01/16/2009 (8:08 am) · 8 replies

Hello,

I am wondering something

I am trying to find the script involved to attach a behavior to a script from within the script and not in the level editor

Thank You

About the author

I have been interested in game development for around 10 years, it has always remained a hobby. I am now looking to develop my skills and maybe progress it from a hobby into a 2nd income.


#1
01/16/2009 (11:11 am)
Hey Martyn,

A very good question... you should be able to do it like this, I'll use "MyBehavior" as the name of the behavior and "MyObj" as the name of the object you want to add the behavior too.

%behavior = MyBehavior.createInstance();
MyObj.addBehavior(%behavior);
#2
01/16/2009 (11:22 am)
Excellent thank you, I presume this goes into my object script file?
#3
01/16/2009 (11:23 am)
Whatever script file you want. As long as the references to the behavior name and the object name (or a global variable holding it, like in the fish tutorials).
#4
01/16/2009 (11:26 am)
Thank you very much
#5
01/16/2009 (11:27 am)
Sure, if you have any further issues (or have issues with that) feel free to keep asking :)
#6
01/16/2009 (11:40 am)
Only issue I have is how to define what the behavior does I was planning on using the dealsdamage behavior on a bullet and was unsure how I'd assign what damage it does etc like it does in the level editor
#7
01/16/2009 (11:42 am)
You can edit those same fields in script. When you add a behavior field, you give the field a name... simply change that field's value on the behavior instance... hence a field named "speed"

%behavior = MyBehavior.createInstance();
%behavior.speed = 15;
#8
01/16/2009 (11:49 am)
Oh I understand thank you again :)