Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/06/23 11:29
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
7 registered members (fairtrader, Quad, miwok, Martin_HH, AndrewAMD, alibaba, dpn), 581 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
one action,many entities (diffrent effect on each) #48168
06/21/05 06:08
06/21/05 06:08

A
Anonymous
Unregistered
Anonymous
Unregistered
A



Just thought this bit of code might helpful to someone. It saved me a lot of time in my game from having to write 200 actions to make 200 juggling objects juggle at different sin and cos frequencies. Since my.skill1 through my.skill100 are local variables to an object, one can conform a skill to a global variable accordingly to allow that object to have the same action/function but still have it conform to either when it was created, where exactly it is, etc. This should significantly decrease the amount of everyone's favorite activity: c-script programming. When juggling, if you didn't know, every ball is not thrown at the same time. So here is the function I used in the the ent_create to create more juggling balls without having multiple actions, but still having each ball moving in the pattern at the correct frequency:

function juggleobject()
{
my.skill1=2;fakecount+=1;my.skill60=fakecount;my.skill1=skilly;counter+=1;counter%=2;
if(counter==1){my.skill70=1;}else{my.skill70=-1;}
if(counter==0){my.skill80=0;}else{my.skill80=-180;}
my.material=sam;
while(1){
if(baco==0){my.material=sam;}if(baco==1){my.material=e1;}if(baco==2){my.material=e2;}
if(baco==3){my.material=e3;}if(baco==4){my.material=e4;}if(baco==5){my.material=e5;}
if(baco==6){my.material=e6;}
if(baco==7){if(my.skill60%6==0){my.material=e1;}if(my.skill60%6==1){my.material=e2;}
if(my.skill60%6==2){my.material=e3;}if(my.skill60%6==3){my.material=e4;}
if(my.skill60%6==4){my.material=e5;}if(my.skill60%6==5){my.material=e6;}}
if(frc((fakecount/4))==0){my.skill90=even;}else{my.skill90=my.skill80;}
vec_set(my.skill13,my.x);my.skill12=fsin(my.roll,-20);my.skill11=fcos(-my.roll,-20);my.skill10=0;
vec_add(my.skill13,my.skill10);
if(key_ctrl==on)
{effect(flame,8*time,my.skill13,nullvector);
effect(smoke,8*time,vector(my.skill13+fcos(total_ticks*10,10),my.skill14+fcos(total_ticks*10,10),my.skill15+20),nullvector);};
if(my.skill1==1){ent_morph(my,sphere_mdl);my.skill1=0;};
if(my.skill1==2){ent_morph(my,ball_mdl);my.skill1=0;};
if(my.skill1==3){ent_morph(my,box_mdl);my.skill1=0;};
if(my.skill1==4){ent_morph(my,club_mdl);my.skill1=0;};
if(my.skill1==5){ent_morph(my,ring_mdl);my.skill1=0;};
if(my.skill1==6){my.facing=on;ent_morph(my,cloud_pcx);my.skill1=0;};
if(frc(fakecount/2)!=0)
{ my.invisible=off;
my.x=-width*cos((total_ticks*8*rev)+(timing*(my.skill60-1)));
my.z=-height*cos((total_ticks*16*rev+(timing*(my.skill60-1)*2))-45);
if(skilly==4){my.roll=(-total_ticks*16*spin)+(timing*(my.skill60-1)*2)-90;};
}else{if(frc(fakecount/2)==0)
{
my.invisible=off;my.x=((width/2)*cos((timing*(my.skill60-1)+my.skill90)+(total_ticks*16*rev)))+(my.skill70*width);
my.z=-1*my.skill70*height*sin((timing*(my.skill60-1)+my.skill90)+(total_ticks*16*rev));if(skilly==4){my.roll=(-total_ticks*16*spin)+timing*(my.skill60-1)+90;}}
else{my.invisible=on;}}
if(count<my.skill60){fakecount-=1;counter+=1;ent_remove(my);break;}
wait(1);};
}

Ok, forget about everything here related to its material and path and all that excess stuff that's just for looks, the main thing I wanted to relate is that the global variable (fakecount in this case) is saved into a skill60 (this variable tells how many objects there are), that skill60 could be used to time its path (motion of object is at the bottom part of the function) perfectly according to how many objects are being juggled (fakecount). In other words, the global variable will change each objects skill to how many objects there are, so that skill can be used to time its movement correctly (if you're juggling 3 balls, there's gonna be about 1/2 as much time between each throw as if you were juggling 6 balls right?). So using these local variables, skills can be helpful in applying a formula to each object according to a global factor/variable. In this case its just the amount of balls already there (when it was created). Also in this case the global variable was increasing each time an object was created so I just placed that in the created-object's function. This might save you a lot of time if you're making hundreds of entities. I could use this for a whole lot of objects, but after juggling about 75, framerates get so low, you can't even tell the difference! I think 500 models is the default maximum. This can also apply to particles (my.skill_a through my.skill_z). You could also even have the skills be applied to a global FUNCTION. I'm just hoping to save you guys some time.....

"Those who are faithful with little, will be entrusted with much" -Albert Einstein quoting Jesus Christ

Re: one action,many entities (diffrent effect on e [Re: ] #48169
06/07/06 05:13
06/07/06 05:13
Joined: Aug 2005
Posts: 218
Z
ZZZgames Offline
Member
ZZZgames  Offline
Member
Z

Joined: Aug 2005
Posts: 218
Cool .These days i was thinking about the same kind of system to link the behaviour of several entities to one global variable...This would help in a game where the entities must know the datas of other entities to create a group behaviour.

About the framerates that gets low with 75 models, is that because of the code or because of the number of polygons?
Anyway i learnt few things....Can you believe that i didnot know the trick of
[counter+=1;counter%=2;] ?
If i understood well ,that makes counter = 1,0,1,0,1,0,1 ...etc.. at each cycle ..right?
How useful is that?(though i might have a clue)


Its a pleasure to play around with A6. zzzgames.ifrance.com : go try & buy Streetkicker
Re: one action,many entities (diffrent effect on e [Re: ZZZgames] #48170
06/07/06 20:38
06/07/06 20:38
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline
Serious User
Lion_Ts  Offline
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
Simple and fresh, WING.
But effective and usefull.
Thanks, man.


Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1