Coding
by Joe Banko · in Technical Issues · 03/03/2008 (2:26 pm) · 5 replies
I have the following datablock:
new t2dSceneObjectDatablock(Ship)
{
name = "none";
type = "none";
missileSpeed = 0;
};
I have in another script file:
function enemy::Spawn(%eType)
{
%this.name = "badboy";
%this.type = %eType;
%this.size = "40.000 24.000";
...
...
...
%this.setAnimation("S1ImageAnimation");
%this.setLinearVelocityX(-150);
%this.missileSpeed = -200;
}
I have in the start game function:
$eShip = new t2dAnimatedSprite(Name:Ship);
$eShip.class = "enemy";
$eShip.spawn("SH1");
I get a console error "spawn not found"
If I put the code in enemy::spawn in place of:
$eShip.spawn("SH1");
I get my sprite running across the screen like it should. If I change the name of the function to just spawn and add another parameter like this:
function spawn(%this,%eType)
...
...
...
and replace:
$eShip.spawn("SH1");
with:
spawn($eShip,"SH1");
That also works but is NOT what I want. What am I missing???????
I want a script file that defines attributes and functions for an "enemy" and script files for "friend" and "sObject" and other objects that have their own functions that I can call and the object, like $eShip above will know what functions to execute. I just don't get it.
Help!!!!!!
Thanks,
jb
new t2dSceneObjectDatablock(Ship)
{
name = "none";
type = "none";
missileSpeed = 0;
};
I have in another script file:
function enemy::Spawn(%eType)
{
%this.name = "badboy";
%this.type = %eType;
%this.size = "40.000 24.000";
...
...
...
%this.setAnimation("S1ImageAnimation");
%this.setLinearVelocityX(-150);
%this.missileSpeed = -200;
}
I have in the start game function:
$eShip = new t2dAnimatedSprite(Name:Ship);
$eShip.class = "enemy";
$eShip.spawn("SH1");
I get a console error "spawn not found"
If I put the code in enemy::spawn in place of:
$eShip.spawn("SH1");
I get my sprite running across the screen like it should. If I change the name of the function to just spawn and add another parameter like this:
function spawn(%this,%eType)
...
...
...
and replace:
$eShip.spawn("SH1");
with:
spawn($eShip,"SH1");
That also works but is NOT what I want. What am I missing???????
I want a script file that defines attributes and functions for an "enemy" and script files for "friend" and "sObject" and other objects that have their own functions that I can call and the object, like $eShip above will know what functions to execute. I just don't get it.
Help!!!!!!
Thanks,
jb
About the author
#2
Instead of making a new datablock I should define Ship as a new t2dAnimatedSprite with attributes that I want (name, missileSpeed, position, etc. and THEN assign $eShip as a new Ship? If so then how do I define the functions that I want an "enemy" to execute? Or do I create an instance of Ship as an Enemy and then use Enemy::xfunction to define the actions? I'm a lot fuzzy here.....
Thanks,
Joe B
03/04/2008 (2:03 pm)
And here is where my confusion starts........Instead of making a new datablock I should define Ship as a new t2dAnimatedSprite with attributes that I want (name, missileSpeed, position, etc. and THEN assign $eShip as a new Ship? If so then how do I define the functions that I want an "enemy" to execute? Or do I create an instance of Ship as an Enemy and then use Enemy::xfunction to define the actions? I'm a lot fuzzy here.....
Thanks,
Joe B
#3
PS: I'm not 100% sure using "Name:Ship" will have the desired effect. I've never seen it attempted, so I'm not sure if it will cause any issues or not off the top of my head.
One more edit: your use of ".name" in your spawn function will not accomplish anything either--the only "name" that matters is what you put between the ( ) as part of the new operation.
03/04/2008 (2:36 pm)
Namespaces are initialized as part of the object creation process. You cannot change a namespace once an object has been created simply by changing the field ".class" to a new value--you have to do it in the creation of the object itself, like so:$eShip = new t2dAnimatedSprite(Name:Ship) {
class = "enemy";
scenegraph = <insert your scenegraph name here>; // note: this line is very important--script generated
// objects do not get put in a scenegraph automatically.
};PS: I'm not 100% sure using "Name:Ship" will have the desired effect. I've never seen it attempted, so I'm not sure if it will cause any issues or not off the top of my head.
One more edit: your use of ".name" in your spawn function will not accomplish anything either--the only "name" that matters is what you put between the ( ) as part of the new operation.
#4
Instead of making a new datablock I should define Ship as a new t2dAnimatedSprite with attributes that I want (name, missileSpeed, position, etc. and THEN assign $eShip as a new Ship? If so then how do I define the functions that I want an "enemy" to execute? Or do I create an instance of Ship as an Enemy and then use Enemy::xfunction to define the actions? I'm a lot fuzzy here.....
Thanks,
Joe B
03/04/2008 (2:37 pm)
And here is where my confusion starts........Instead of making a new datablock I should define Ship as a new t2dAnimatedSprite with attributes that I want (name, missileSpeed, position, etc. and THEN assign $eShip as a new Ship? If so then how do I define the functions that I want an "enemy" to execute? Or do I create an instance of Ship as an Enemy and then use Enemy::xfunction to define the actions? I'm a lot fuzzy here.....
Thanks,
Joe B
#5
$eShip1 = new Ship();
And
$eShip1.Spawn($eShip1,"SH1");
gets me into the
Ship::Spawn(%this,%eType)
function but %eType evaluates to the same value as %this. And it won't switch to the correct animation but always takes the default.
switch$(%eType)
{
case("SH1):
...
...
case("SH2"):
...
...
default:
ALWAYS GOES HERE<<<<<
Why is %eType changing "SH1" to a number? I've tried using 'SH1' but get the same behavior. Gotta be something simple. BTW, thanks Ross, you got me thinking in the right direction.
Joe B
03/04/2008 (3:50 pm)
Making a new t2dAnimatedSprite(Ship) allows me to create all the little ships I want just by:$eShip1 = new Ship();
And
$eShip1.Spawn($eShip1,"SH1");
gets me into the
Ship::Spawn(%this,%eType)
function but %eType evaluates to the same value as %this. And it won't switch to the correct animation but always takes the default.
switch$(%eType)
{
case("SH1):
...
...
case("SH2"):
...
...
default:
ALWAYS GOES HERE<<<<<
Why is %eType changing "SH1" to a number? I've tried using 'SH1' but get the same behavior. Gotta be something simple. BTW, thanks Ross, you got me thinking in the right direction.
Joe B
Associate Ross Pawley