Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,633 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Question about pointers #118427
03/20/07 14:46
03/20/07 14:46
Joined: Mar 2007
Posts: 47
Columbus Ohio
S
sweetpickles Offline OP
Newbie
sweetpickles  Offline OP
Newbie
S

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
V
vlau Offline
Serious User
vlau  Offline
Serious User
V

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: vlau] #118429
03/20/07 17:31
03/20/07 17:31
Joined: Mar 2007
Posts: 47
Columbus Ohio
S
sweetpickles Offline OP
Newbie
sweetpickles  Offline OP
Newbie
S

Joined: Mar 2007
Posts: 47
Columbus Ohio
First question: Thanks.

Second question: Using the missile example; let's say that there are several missiles in the air at the same time. Let's say the player has a way of destroying all enemy missiles. I was assuming that I could destroy anything that was a "projectile". Am I simply approaching this challenge the wrong way? Is there a simpler way of creating/controlling/destroying similar objects within 3DGS?

Third question: I'm still a little confused about the reasons to use pointers. I'm not going to continue down the path of my third question until I figure it out a little more.

I think I may be approaching 3DGS with the wrong mindset. I'm used to having to create entities and control each of them with a type/for/each command. It would seem that 3DGS does this for me, I just have to tell it how to move an entity within a function/action and let collision detection do it's job. If this is true, then how useful are pointers? Are they there just to make it easier to access the properties of single entities?

Re: Question about pointers [Re: sweetpickles] #118430
03/20/07 17:46
03/20/07 17:46
Joined: Aug 2005
Posts: 1,558
HK
V
vlau Offline
Serious User
vlau  Offline
Serious User
V

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: vlau] #118431
03/20/07 18:12
03/20/07 18:12
Joined: Mar 2007
Posts: 47
Columbus Ohio
S
sweetpickles Offline OP
Newbie
sweetpickles  Offline OP
Newbie
S

Joined: Mar 2007
Posts: 47
Columbus Ohio
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?

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?

Thanks for your patience, by the way.

Re: Question about pointers [Re: sweetpickles] #118432
03/20/07 18:30
03/20/07 18:30
Joined: Aug 2005
Posts: 1,558
HK
V
vlau Offline
Serious User
vlau  Offline
Serious User
V

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: vlau] #118433
03/20/07 18:38
03/20/07 18:38
Joined: Mar 2007
Posts: 47
Columbus Ohio
S
sweetpickles Offline OP
Newbie
sweetpickles  Offline OP
Newbie
S

Joined: Mar 2007
Posts: 47
Columbus Ohio
Your explanations have been great. And I appreciate you taking the time to help me learn. I think I was over-complicating things.

So how are pointers best used? By that I guess I'm wondering what purpose is there that best makes use of them?

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
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

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!
Re: Question about pointers [Re: JibbSmart] #118435
03/20/07 20:53
03/20/07 20:53
Joined: Mar 2007
Posts: 47
Columbus Ohio
S
sweetpickles Offline OP
Newbie
sweetpickles  Offline OP
Newbie
S

Joined: Mar 2007
Posts: 47
Columbus Ohio
player=me

That makes good sense. Anything else? I vaguely understand your wheel loop. Not at the level where it makes instant sense though.

I'm looking through the manual now to see how a few other things work.


Gamestudio download | 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