|
3 registered members (TipmyPip, alibaba, 1 invisible),
5,580
guests, and 2
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Question about pointers
#118427
03/20/07 14:46
03/20/07 14:46
|
Joined: Mar 2007
Posts: 47 Columbus Ohio
sweetpickles
OP
Newbie
|
OP
Newbie
Joined: Mar 2007
Posts: 47
Columbus Ohio
|
Before I ask my questions, here's my programming background... Programmed BASIC on Vic20, C-64, TRS 80 CoCo back in the day. Most recently learned scripting for Neverwinter Nights (completed several modules) and some Blitz Basic. Decided that I didn't want to write my own engine and am thinking about buying 3DGS. Played with the demo a little (before reading manuals) and essentially wasted my 30 days. I read through the C-Script manual and now have a question about pointers (which I have never used before). I just want to make sure I understand them correctly. First question: If I declare this... Code:
entity* projectile;
And I make a "missile" entity and assign it an action such as... Code:
action assign_projectiles { projectile=me; }
I can then address the missile entity using something such as... Code:
projectile.x += intXoffset;
Am I correct in this assumption? Second question: Assuming the above is correct, can I assign the "assign_projectiles" action to other entities and control them all simultaneously using the projectile pointer? Third question: Can an entity (or anything else for that matter) have multiple pointers assigned to it?
|
|
|
Re: Question about pointers
[Re: sweetpickles]
#118428
03/20/07 15:46
03/20/07 15:46
|
Joined: Aug 2005
Posts: 1,558 HK
vlau
Serious User
|
Serious User
Joined: Aug 2005
Posts: 1,558
HK
|
First question : You're absolutely right. Second question : Usually an entity pointer refer to a single object at the same time, in your example, there will be no error but the engine didn't know which missile you're refer to at runtime, so better rewrite your code with my or me pointer as follow : Code:
function moveMe() { my.x += intXoffset; }
action assign_projectiles { ..... while (my != NULL) { moveMe(); wait(1); } }
Then, each entity (missile) has their own movement. Third question : It is possible also, but why doing this way?
|
|
|
Re: Question about pointers
[Re: sweetpickles]
#118430
03/20/07 17:46
03/20/07 17:46
|
Joined: Aug 2005
Posts: 1,558 HK
vlau
Serious User
|
Serious User
Joined: Aug 2005
Posts: 1,558
HK
|
First question : You're welcome  Second question : You can do it the same as I wrote above : Code:
action assign_projectiles { ..... while (my != NULL) { moveMe(); checkCollision(); wait(1); } // or write all the above functions inside this action }
With single action assign to different objects, each object has their own movement and collision detection. Third question : Sometimes, for example, you may refer to this object within other actions, then you may need it.
Last edited by vlau; 03/20/07 17:47.
|
|
|
Re: Question about pointers
[Re: sweetpickles]
#118432
03/20/07 18:30
03/20/07 18:30
|
Joined: Aug 2005
Posts: 1,558 HK
vlau
Serious User
|
Serious User
Joined: Aug 2005
Posts: 1,558
HK
|
Quote:
So is an action essentially a behavior that you assign to an entity? For instance, I would write an action for "missiles" and an action for "mortars" and an action for "med-kits", etc. and then assign these actions to the appropriate entities?
Yes, otherwise the engine never know how to operate the entity.
Quote:
If that's the case, then when creating a missile entity spontaneously within the game (i.e. player fires a missile), would I use a pointer to assign an action to it or is that unnecessary?
You can assign a pointer and/or assign an action to it direcrtly by using ent_create(...) or in WED, as I said, the entity pointer can be used in other entity's action.
Quote:
Thanks for your patience, by the way.
I hope my explanation is clear and you'll get it.
|
|
|
Re: Question about pointers
[Re: sweetpickles]
#118434
03/20/07 20:19
03/20/07 20:19
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
i'm using the lite-c beta and it allows for local pointers and arrays of pointers. in my car game each car has near the beginning of its action an empty array of pointers: ENTITY* wheel[4]; and then creates each of the wheels. when one entity creates another entity, it returns a pointer to that entity just created. so, i have a loop as follows: Code:
var i = 4; while(i>0) { i -= 1; wheel[i] = ent_create("wheel.mdl",nullvector,wheelAct); }
now each car has pointers to each of its wheels and can do with them however it wants. i'm not sure if c-script (which is similar to lite-c except slightly easier and slightly less feature-rich) can use local pointers or arrays of pointers. maybe someone else can point that out. but a common use is having a global pointer declared early on in ur script (outside of any function): ENTITY* player; then at the beginning of the main character's action you have "player = me;" then all the badguys can refer to they player however they want (check distance between them and the player, or other stuff). if you want to give a whole bunch of entities some sort of id, you could set one of their skills to indicate if they are a missile. for example, in the missile action, say my.skill5 = 1; if u make sure no non-missile entities change their skill5 from 0, then u can easily find all the missiles using a while loop and ent_next(). look up ent_next in the manual -- it can be very useful. basically it is used to search through all the entities. i hope this helps! julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|