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
3 registered members (NewbieZorro, TipmyPip, 1 invisible), 19,045 guests, and 8 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
How to make structs do anything? #226823
09/11/08 14:29
09/11/08 14:29
Joined: Aug 2008
Posts: 55
United Kingdom
CdeathJD Offline OP
Junior Member
CdeathJD  Offline OP
Junior Member

Joined: Aug 2008
Posts: 55
United Kingdom
Ok so i'm having trouble with structs, it seems that they can only be used to statically create 3d objects, as there is no way of referencing them afterwards... heres my lates nemesis:

=================================================================

typedef struct
{
var lifetime;
ENTITY* model;
} box;


function i_am_fly()
{
my.lifetime -= 1;
if (my.lifetime < 1)
{
ent_remove(my_box.model);
}
}

function new_box()
{
box my_box;
my_box.model = ent_create("cube_small.x",vector(0,0,0),NULL);
my_box.function = i_am_fly();
/* some 3d object set up stuff */
my_box.lifetime = 100;
c_setminmax(my_box.model);
wait(1);
/* some object physics set up stuff */
num_box=num_box+1;
}
}
wait(1);
}

===============================================================

There is very little information on using structs in the manual really, theres no examples of getting data from them and no information on how to remove a struct entry altogether.

However i saw that *effects* use something called "my.function* to make stuff happen to their particles after creation and assumed this works for structs also. I'm also assuming that the assigned function is run once per struct entry per frame?

However the code above doesn't work as lite-c tells me the line "my.lifetime -= 1;" is giving the error: ".lifetime is not a member of ENTITY".

Which is wrong as i defined it in the struct defenition!!!!

Last edited by CdeathJD; 09/11/08 14:30.

I am a noob to this... Blitz3D is where i am best at!
Re: How to make structs do anything? [Re: CdeathJD] #226877
09/11/08 20:29
09/11/08 20:29
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline
Serious User
Happy Birthday Scorpion  Offline
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
lifetime is a member of PARTICLE* but not of ENTITY*. I think you messed up these 2. Look it up in the manual more exactly.

To access objects in structs you should use the arrow operator "->" instead of a dot ".".

And you did something wrong: the struct doesn'T contain any object with the name 'function', so you can't access it. BUT the ENTITY* object in the struct contains such. So write:

Code:
my_box->model->function = i_am_fly;//moves the model on the x-axe


Re: How to make structs do anything? [Re: Scorpion] #226944
09/12/08 03:15
09/12/08 03:15
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
A struct doesnt actually 'do' anything. Its just a group of variables and
pointers you are lumping together for ease of access.

Heres a rough interpretation of what your trying to do, even though I cant
see why you'd want to, at least this way. There are many easier ways to do
what I THINK you want, which I'll post if you ask.
Code:
typedef struct
{
   var lifetime;
   ENTITY* model;
} box; 


function i_am_fly(box* ThisBox)
{
   ThisBox.lifetime -= 1;
   if (ThisBox.lifetime < 1)
   {
      ent_remove(ThisBox.model);
      //	Add the following line ALSO if you want to remove BOX struct too
      //ptr_remove(ThisBox);	
   }
}

function new_box()
{
   box my_box;
   my_box.model = ent_create("a.mdl",vector(0,0,0),NULL);
   //my_box.function = i_am_fly();   //<<<<<< replaced lower down
   /* some 3d object set up stuff */
   my_box.lifetime = 100;
   c_setminmax(my_box.model);
   wait(1);
   /* some object physics set up stuff */
   i_am_fly(my_box);              //<<<<<<<<<< only new line in new_box() 
   num_box=num_box+1;
   ... 


Any questions? Please ask.

PS please try to enclose large hunk of coding in the "code" blocks as I
have here. Its under the "#" toolbutton on the "Posting" toolbar.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: How to make structs do anything? [Re: EvilSOB] #227024
09/12/08 12:03
09/12/08 12:03
Joined: Aug 2008
Posts: 55
United Kingdom
CdeathJD Offline OP
Junior Member
CdeathJD  Offline OP
Junior Member

Joined: Aug 2008
Posts: 55
United Kingdom
I seee!

Code:
#include <acknex.h>
#include <default.c>

ENTITY* FLOOR;
var ypos;
var hello;
var angle1;
VECTOR box_rotation;
VECTOR centre = vector(0,0,0);

var num_box;
var new_ball_delay;
var iveruntheIamFlyfunk;

typedef struct
{
	var lifetime;
	ENTITY* model;
} box; 

function i_am_fly(box* Thisbox)
{
	iveruntheIamFlyfunk += iveruntheIamFlyfunk;
	Thisbox.lifetime -= 1;
	if (Thisbox.lifetime < 1)
	{
		ent_remove(Thisbox.model);
		ptr_remove(Thisbox);
	}
}
  
function new_box()
{
	ypos = 10;
	while (ypos < 450) 
	{
		ypos = (ypos + 25);
		angle1 = 0;
		while (angle1 < 360)
		{
		angle1 += 360;
		box my_box;
                
                /*box object setup stuff */

		c_setminmax(my_box.model);
		wait(1);

		/*box physics setup stuff */

		num_box=num_box+1;
		i_am_fly(my_box);
	}
	}
	wait(1);
}


Heres the thing though, when the new_box() function is called, it runs, however the special variable i added to check if the "i_am_fly" function was running, "iveruntheIamFlyfunk;" does not increment!

Regardless... what i am trying to do is essentially make some sort of crude particle system, which is where the "lifetime" var comes in. So really it wouldn't be any good just having the i_am_fly() funk running (if SED gives up its prejudice and runs it at all!), once per object, it would have to run repeatedly per frame or the lifetime var wouldn't decrease to the death point for the object!


I am a noob to this... Blitz3D is where i am best at!
Re: How to make structs do anything? [Re: CdeathJD] #227055
09/12/08 13:39
09/12/08 13:39
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Sorry, my bad. I left out a layer of thinking.


Code:
function i_am_fly(box* Thisbox)
{
	while(Thisbox.lifetime>0)
	{
		wait(1);			//wait 1 frame
		Thisbox.lifetime -= 1;	//reduce counter
	}
	ent_remove(Thisbox.model);		//remove timed-out model
	ptr_remove(Thisbox);		//remove empty box
}

Does this explain my intention better?


Cause if Ive got it right, and you JUST want to have a time-out counter,
you could look into using the entities "skills". Below is an exact copy of whats happening above.
Code:
/// Assume in new_box you said 
...
my_model = ent_create("cube_small.x",vector(0,0,0),NULL);
my_model.skill25 = 100;
i_am_Dying(My_Model);
...

function i_am_dying(ENTITY* ThisModel)
{
	while(ThisModel.skill25>0)
	{
		wait(1);			//wait 1 frame
		ThisModel.skill25 -= 1;	//reduce counter
	}
	ent_remove(ThisModel);		//remove timed-out model
}


Interesting? 100 built-in variables in every entity. Or is this old news to you?


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: How to make structs do anything? [Re: EvilSOB] #227066
09/12/08 14:04
09/12/08 14:04
Joined: Aug 2008
Posts: 55
United Kingdom
CdeathJD Offline OP
Junior Member
CdeathJD  Offline OP
Junior Member

Joined: Aug 2008
Posts: 55
United Kingdom
Ok thanks for that it works, what i dont get is how. The i _am_dying function is called during the "new_box" function which is run only once when called by a keypress.

So my understanding is it runs through the "new_box" commands arrives at the function "i_am_dying" and should decrement the first created boxes "skill" parameter to zero, then return to "new_box" and create the next one, then kill it, so at most what i should see is a one-box at a time version... i dont understand :S!


I am a noob to this... Blitz3D is where i am best at!
Re: How to make structs do anything? [Re: CdeathJD] #227096
09/12/08 16:02
09/12/08 16:02
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Easy place to get confused. The trick is in my next statement.
*** 3DGS is multi-tasking ***
That probably doesnt help, but I will explain.

With the your/our sample code an example it processes like this.
Its a long read, but read right through and then light will begin to shine.

1> new_box() runs through until it transfers control to i-am-dying, then PAUSES.

2> i_am_dying runs through until it hits the wait(1); statement, then WAITS UNTIL NEXT FRAME.

3> Because i_am_dying is waiting, new_box now UN-pauses and continues on.

4> new_box continues on till it FINISHES and returns control back to whatever function called it. We'll call it "Master".

5> Master will carry on until IT hits a wait(?); statement, then IT waits for next frame.

6> Other background stuff happens, during which THE NEXT FRAME STARTS.

7> Now i_am_dying has been waiting the longest so now it CONTINUES from where it was.
It decrements the counter, loops back to the while() statement and does the check. If it still has life left, it
goes into the loop, hits the wait(1); and wait for the NEXT FRAME.

8> Now control passes to the function in the "WAITing queue", which happens to be Master.

9> Master loops over and calls new_box again.

10> new_box then trundles through, creating a NEW box and a new entity to put in it.
***IMPORTANT***it created a NEW box, and it passes that box to ANOTHER COPY of i_am_dying.

11> goto step 2

Insert at 7A
7A> Now i_am_dying instance # 2 has been waiting the its turn so now it CONTINUES from where it was.
It decrements the counter, loops back to the while() statement and does the check. If it still has life left, it
goes into the loop, hits the wait(1); and wait for the NEXT FRAME.
Otherwise, like i_am_dying instance # 1 will also be doing, the counter has run out, so this
box self terminates CLOSES this COPY of the i_am_dying function. It passes control back to the "WAITing queue".

Pretty hairy stuff, but look at this, then the code, and back a few times it will make sense.
Probably.....Kind Of.......I hope.......

Ah well. Any questions, fire away.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: How to make structs do anything? [Re: EvilSOB] #227171
09/12/08 22:05
09/12/08 22:05
Joined: Aug 2008
Posts: 55
United Kingdom
CdeathJD Offline OP
Junior Member
CdeathJD  Offline OP
Junior Member

Joined: Aug 2008
Posts: 55
United Kingdom
Ok thats confusing me lol. So what your saying is "wait(?)" isn't so much of a "render the scene now" command as a "stop this function till the next function main() loop starts"?


I am a noob to this... Blitz3D is where i am best at!
Re: How to make structs do anything? [Re: CdeathJD] #227175
09/12/08 22:26
09/12/08 22:26
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Close, well done. Main is not necessarily the first in the queue.

Its more a
"Pause this function until all other queued functions have had ONE turn at this frame,
then unpause this function WHEN its turn in the queue arrives next frame.


Or even more simply (and a little too simple)
"Pause this function until THIS FRAME has been drawn.

This is not an easy concept, but once you get it you'll wonder why it seemed so hard.

What happens is, whenever ANY function hits a WAIT()it pauses.
This continues until ALL functions are paused, then the current FRAME is drawn.
Then the functions are un-paused one-by-one, in approximately the same order they got paused in.
Each function will un-pause, run its code until it hits a wait(), then re-pause.
Then the next function in the queue will take its turn, etc, until all have had one turn this frame.
Then the now current frame get drawn, and the cycle starts again with the first function in the
queue getting called and so on.



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

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

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