Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Akow), 1,403 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Problems with entity #117696
03/16/07 13:56
03/16/07 13:56
Joined: Mar 2007
Posts: 27
P
PeterM Offline OP
Newbie
PeterM  Offline OP
Newbie
P

Joined: Mar 2007
Posts: 27
Helo I am just starting with c-scrypting and i want to create a throwing rock function.
at the beggining entity rock is created then i set its pan and tilt the same as cameras and started to move it with reducing dist.x and dist.z. here is the code...

function naredi_entity()
{
vec_for_vertex(zac,snezak,589);
my=ent_create("kepa.mdl",zac,NULL);
wait(20);
my.pan=camera.pan;
my.tilt=camera.tilt;
k=k+1;
h=zac_h;
i=1;
while (1)
{

dist.x=h*time;
if (h>0)
{
h=h-0.15;
}
i=i+0.12;
dist.z=i*time*-1;
move_mode=ignore_passable;
camera.tilt = clamp(camera.tilt,-10,10);
camera.pan=clamp(camera.pan,-10,10);

vec_set(camera.x,vector(my.x + fcos(camera.pan,temp),my.y +
fsin(camera.pan,temp),my.z + 8 + fsin(camera.tilt,-camera_distance)));
ent_move(dist,nullvector);

wait(1);
}
}

Now my problem is when i want to throw another rock previus rock is moving to...
Please help me or direct me to a tutorial or something.

TNX

Re: Problems with entity [Re: PeterM] #117697
03/16/07 14:24
03/16/07 14:24
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
I think I know where your problem lies. For throwing another rock, it overwrites the previous rock's variables, right?
The ppl who developed c_script were smart enough for that though. Each entity has it's own 100 variables, called skills. you access them by using "entity.skill1" - "entity.skill100".
so, instead of h, you could write my.skill2, for example.
Just so you can keep track of what the skill does, what variable it represents, you could do this:
define h, skill2;

and delete your var h; statement that you probably have somewhere in your code right now.
now, you can use "myh" instead of just h, and thus each entity has it's own set of variables, that don't interfere with the other's variables.
Now you'll run into another problem. "my" gets overwritten every time you throw a new rock, by the statement "my = ent_create(...);".
so... what I'd do is, let every entity run it's own action. basically, put everything the entity is supposed to do into it's own action, that get's executed automatically if in this line " my=ent_create("kepa.mdl",zac,NULL);" you replace null by the function name.

inside this function (or, in this case, i used an action, which for our purpose is the same deal), "my" is always referring to the entity that runs the action, unless you redefine it (using my = ...;)...

Code:


var k;
define h,skill1;
define i,skill2;

action the_rock
{
my.pan=camera.pan;
my.tilt=camera.tilt;
k += 1; //programmers are slack. k+=...; is the same as writing k=k+...;
my.h=zac_h;
my.i=1;
while (1)
{

dist.x=my.h*time;
if (my.h>0)
{
my.h -= 0.15;
}
my.i += 0.12;
dist.z=my.i*time*-1;
move_mode=ignore_passable;
camera.tilt = clamp(camera.tilt,-10,10);
camera.pan=clamp(camera.pan,-10,10);

vec_set(camera.x,vector(my.x + fcos(camera.pan,temp),my.y +
fsin(camera.pan,temp),my.z + 8 + fsin(camera.tilt,-camera_distance)));
ent_move(dist,nullvector);

wait(1);
}
}

function naredi_entity()
{
vec_for_vertex(zac,snezak,589);
ent_create("kepa.mdl",zac,the_rock); //the function "the_rock" must be somewhere before this line,
//otherwise it won't find it when it get's to this line, and give you an error message.
}




try this. not tested, hope it works....
if you've got any questions as to why i wrote something the way i did, please ask!

Micha


~"I never let school interfere with my education"~
-Mark Twain
Re: Problems with entity [Re: Germanunkol] #117698
03/16/07 15:40
03/16/07 15:40
Joined: Mar 2007
Posts: 27
P
PeterM Offline OP
Newbie
PeterM  Offline OP
Newbie
P

Joined: Mar 2007
Posts: 27
Thank you very much It works fine now.
I am still learning and there is a lot of things i dont fully understand... like skills... but ill get there eventualy:)

How do i exit while(1)? i want that when rock reaches the ground or something else that while(1) stops running. I read somewhere that it would stop if i destroy entity... but i dont want that. i just want to terminate action and leave the entity there...


tnx again

Last edited by PeterM; 03/16/07 15:54.
Re: Problems with entity [Re: PeterM] #117699
03/16/07 15:54
03/16/07 15:54
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
no problem ...
seems like you got the maths down pretty good though. using sine and cosine in game before understanding skills... not bad
Good luck with learning, and glad I could help!


~"I never let school interfere with my education"~
-Mark Twain
Re: Problems with entity [Re: Germanunkol] #117700
03/16/07 16:10
03/16/07 16:10
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
while() loops will run as long as their statements are true(1). Since you are using a while(1), it will continuaously run, because it will always be true(1).

If you replace the (1) with a variable, then you could simply set that variable to false(0) to end the loop. while(my.skill1 > 0) will run as long as the entities first skill (skill1) is larger than 0.

Last edited by xXxGuitar511; 03/16/07 16:11.

xXxGuitar511
- Programmer
Re: Problems with entity [Re: xXxGuitar511] #117701
03/16/07 17:04
03/16/07 17:04
Joined: Mar 2007
Posts: 27
P
PeterM Offline OP
Newbie
PeterM  Offline OP
Newbie
P

Joined: Mar 2007
Posts: 27
Germanunkol yes i am using sine and cosine but i dont quite get it yet:) i just know that this will get me 3rd person view (i copyed it from a tutorial )

tnx for reply xXxGuitar511 I will try it out.
How can I check if my rock hitted another entity, flor or walls? is there any coalition detecting function?

Last edited by PeterM; 03/16/07 17:11.
Re: Problems with entity [Re: PeterM] #117702
03/16/07 19:12
03/16/07 19:12
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
there's a whole bunch of them, yes

basically, what you do is write another function, BEFORE the rock's action.
for example:

function rock_event()
{
...
}

then inside your the_rock action, the first three lines should be:
my.enable_entity = on;
my.enable_block = on;
my.event = rock_event;

what this does is: first you make it "vulnerable" to entity and block colision. this will only work with ent_move (or the never version, c_move), which you use, so that's fine. so, now you tell it to run it's "event" function every time it hits an entity or a block. then, in the third line, you tell it what that event function is.
now, inside the function rock_event you put something like this:
if(event_type == event_entity)
{
...
]
if(event_type == event_block)
{
...
}

instead of the "..." you put in what you want to happen (like changing the direction of flight of the rock etc) if the thing that happened (event_type) is that it hit a block (event_block) or if it hit an entity (event_entity) while moving.
hope that's understandable...?

Micha


~"I never let school interfere with my education"~
-Mark Twain
Re: Problems with entity [Re: Germanunkol] #117703
03/18/07 11:43
03/18/07 11:43
Joined: Aug 2006
Posts: 128
Papua New Guinea
I
Impaler Offline
Member
Impaler  Offline
Member
I

Joined: Aug 2006
Posts: 128
Papua New Guinea
This is something mentioned previously in the thread that I don't get:

if you can define skills by:

define health skill1;

why can't you do:

define health my.skill1; ??


Murphey's Law:
<< if anything can go wrong, it will >>

(Murphey was an optimist).
Re: Problems with entity [Re: Impaler] #117704
03/18/07 12:26
03/18/07 12:26
Joined: Mar 2007
Posts: 27
P
PeterM Offline OP
Newbie
PeterM  Offline OP
Newbie
P

Joined: Mar 2007
Posts: 27
Germanunkol TNX for the help it works fine now.

Now afcourse I got a new problem about making a new camera.
I searched over the manual but i couldnt find how to turn it on. I made
view camera2
{
layer=0;
flags=visible
}

now problem is that i dont know how to turn it on. if i set layer to 1 it works fine but i dont want it to be visible allways... and i cant set layer to 0 during the game becouse its read only.

Re: Problems with entity [Re: PeterM] #117705
03/18/07 13:26
03/18/07 13:26
Joined: Oct 2002
Posts: 4,753
Munich, Bavaria, South of Germ...
TripleX Offline
Expert
TripleX  Offline
Expert

Joined: Oct 2002
Posts: 4,753
Munich, Bavaria, South of Germ...
You can use the visible flag of camera2.

Camera2.visible = on;
or
Camera2.visible = off;

Btw: Use layer_sort(object,new_layer); for changing the layer of an object at runtime.

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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