3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1]

Author Topic: target script for "x" towers  (Read 1414 times)

« on: September 22, 2009, 09:35:49 PM »
I have a little question about scripting ^^ :

is it possible to save the object address (OBJ_XX) in a variable for example a string and select the needed object with switch?
(i tried string and it doesn't work)


Vector3 pos1, pos2, pos0, UpLoc;
int x;
Quaternion orientation1;
string tower, target;

void Main()
{


switch(x)
{
case 0:
x=1;
tower = "OBJ_88";
target = "OBJ_22";


break;
case 1:
x=0;
tower = "OBJ_132";
target = "OBJ_154";

break;


};

iObjectLocation(tower,  pos1); //obj_88 = tower
iObjectLocation(target ,pos2); //obj_22 = target

pos0.x = pos1.x-pos2.x;
pos0.y = pos1.y-pos2.y;
pos0.z = pos1.z-pos2.z;

pos1.y += 4;
pos1.z -= 2;

x = iVectorLengthSq(pos0);
if (x < 10000)
{

UpLoc = Vector3(1,1,1);
iQuaternionLookAt(orientation1,pos2-pos1, UpLoc);
iObjectOrientationSet(OBJ_0,orientation1);
 

iObjectLocationSet(OBJ_44,pos2);
iObjectStart(OBJ_44);
}



}
« Reply #1 on: September 22, 2009, 10:04:14 PM »
i think that works with integer:

int tower, target;

and without the quotation marks

tower = OBJ_88;
« Last Edit: September 22, 2009, 10:08:00 PM by loop »
Crashing Boxes - winner of the 3d games category at the 5th Uruguayan video game contest
get a copy for your iPad/iPhone!
« Reply #2 on: September 23, 2009, 04:29:59 AM »
Thanks a lot  ;D works perfect now.

But now i have another question. While trying how to change the active tower i tried a endless loop "while(true)" and got a overflow message. I think its because the script is limited to some executions per second and a loop not, is that right?
« Reply #3 on: September 23, 2009, 04:37:59 AM »
I have no idea.. but, anyway an endless loop dosnt look like something that gonna lead you anywhere. and the script is executed 60 times / second, so if you make to much to process everytime the script is executed then everything gonna go really slow.
Crashing Boxes - winner of the 3d games category at the 5th Uruguayan video game contest
get a copy for your iPad/iPhone!
« Reply #4 on: September 23, 2009, 07:17:17 AM »
I thought the next execute from the script would happen only if it finished all code
the endless loop would start and the script would never go to the next "step" because it can�t come to an end
what will happen if the algorithm in the script is slower than the normal execution time of scripts?

my thought was that a endless loop in a script would be like a hidden script that all the time is executed and the error comes because there is no more time for other objects to react
« Reply #5 on: September 23, 2009, 07:19:13 AM »
If the sum of all your scripts can't execute 60 loops/sec your fps will go down and or hang.
« Reply #6 on: September 23, 2009, 02:17:20 PM »

you're correct there... that's why, unless logic dictates, i would get rid of the loop...

yea, i know :D i just thought it could be used if i need a really fast timer for some reason. ( a loop that will execute more than 60 times a second)

thanks for your help, the script works very well now (and easy to add more towers)

edit:
unfortunately i found 1 more problem where i need your help (about global variable)
i tried to make a lifepoint counter where the health is decreased by a variable but it only decreases 1 time
if VAL_2 is for example 10 the life decreases only one time by ten, if i write -10 direct in the script it is decreased every execution.

here is the code:


int Score, x;
void Main()
{
iObjectStop(OBJ_88);
Score = Score - VAL_2;
OUT_0 = Score/100.0;
OUT_66 = Score;
}
« Last Edit: September 23, 2009, 02:35:42 PM by Mandelbaum »
« Reply #7 on: September 23, 2009, 05:51:57 PM »
this exactly what I want (60 times a second -VAL_2) but this doesn't happen.
Than i have to look in another script connected tho this... propably the bug is somewhere else.

edit:

ok, i found the problem :D
i didn�t know that
OUT_XX += 10;
impossible is but i works fine with
OUT_XX = IN_XX +10;
« Last Edit: September 23, 2009, 06:12:19 PM by Mandelbaum »
Pages: [1]