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
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,534 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Dynamic variables/structs/entintys/etc names #240173
12/09/08 20:42
12/09/08 20:42
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
I was wondering if this could be done...
There are some cases when I dont know on start how many "copies" of a certain item I want to have.
Sometimes I even want tons of them! But I dont want to have to declare tons of variables that I dont know if all are going to be used (or mabe even more than i declare will be needed).

I was wondering if there was any way to create a string (changing the string for each new entity) and using that for its name?

instead of having to use pre-defined names like I do now:
ENTITY* soldier1;
ENTITY* soldier2;
ENTITY* soldier3;
etc...
ENTITY* soldier100;

I just hate doing that!
And also its 100 corresponding actions to attack each different pointer (or 100 ifs in the action to decide which pointer to make = me)

example of what im asking:
Code:
 
int number_of_soldiers;

action Create_Soldier_Name()
{
 STRING* My_ID_Number;
 STRING* New_Entity_Name;

 //set the number
 My_ID_Number = number_of_soldiers;

 //create a string with that number atttacked to it
 New_Entity_Name = "Soldier" & My_ID_Number;
 
 //Somehow use that string as the name/pointer for that entity
 New_Entity_Name = me;
}

void main()
{
 number_of_soldiers = 0;

 while(1)
 {
  if(create_soldier_button == TRUE)
  {
   //update number of soldiers
   number_of_soldiers ++;

   //create a new soldier and go to action to give it its' unique name
   ent_create("grunt.mdl", vector(0,0,0), Create_Soldier_Name)
  }
 }
}


I know that code will not work, but I hope you get what I intend to ask by that example.
Is it posible to do something similar to achieve this?
Mabe also for structs or variables or whatever?


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: Dynamic variables/structs/entintys/etc names [Re: Carlos3DGS] #240177
12/09/08 21:08
12/09/08 21:08
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
What you're asking for is an array. Read the manual under topic "variables". If that is not what you're looking for search for programming lists.


Always learn from history, to be sure you make the same mistakes again...
Re: Dynamic variables/structs/entintys/etc names [Re: Uhrwerk] #240191
12/09/08 22:30
12/09/08 22:30
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
I thought of using arrays at first, but was told that I cannot change the size of the array after it is created and used.

Is it true, or can I cange the size to make an array bigger when it fills up?


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: Dynamic variables/structs/entintys/etc names [Re: Carlos3DGS] #240203
12/09/08 23:15
12/09/08 23:15
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Create an extendable array. But it does come with its own little problems unless you are tidy with your code.
Heres an example, complete (except for model name), compiled & tested.

Code:
#include <acknex.h>
#include <default.c>
//
//
//
ENTITY** soldier;
var max_soldiers;
//
//
function main()
{
   level_load(NULL);      camera.x = -400;   camera.z = -300;   camera.tilt = 45;
   //
   //
   // CREATE initial soldier array
   max_soldiers = 5;                                                 //set initial number of soldiers
   soldier = (ENTITY**)malloc(sizeof(ENTITY*)*max_soldiers);         //create array to hold this many soldier-entities
   soldier[0] = ent_create("cube.mdl", vector(0,10,0), NULL);                //create solder 1
   soldier[1] = ent_create("cube.mdl", vector(0,50,0), NULL);                //create solder 2
   soldier[2] = ent_create("cube.mdl", vector(0,100,0), NULL);               //create solder 3
   soldier[3] = ent_create("cube.mdl", vector(0,150,0), NULL);               //create solder 4
   soldier[4] = ent_create("cube.mdl", vector(0,200,0), NULL);               //create solder 5
   wait(-3);   //pause demo for dramatic effect
   //
   // EXTEND soldier array
   max_soldiers = 10;                                                      //increase number of soldiers
   soldier = (ENTITY**)realloc(soldier, sizeof(ENTITY*)*max_soldiers);     //extend array to hold aditional soldier-entities
   soldier[5] = ent_create("cube.mdl", vector(0,-10,0), NULL);        //create solder 6  in new space
   soldier[6] = ent_create("cube.mdl", vector(0,-50,0), NULL);        //create solder 7  in new space
   soldier[7] = ent_create("cube.mdl", vector(0,-100,0), NULL);       //create solder 8  in new space
   soldier[8] = ent_create("cube.mdl", vector(0,-150,0), NULL);       //create solder 9  in new space
   soldier[9] = ent_create("cube.mdl", vector(0,-200,0), NULL);       //create solder 10 in new space
   //
   wait(-1);   //pause demo for dramatic effect
   soldier[0].x -= 10;   //move old soldier 1 to prove he is still accessable under old name
   soldier[1].x -= 20;   //move old soldier 2 to prove he is still accessable under old name
   soldier[2].x -= 30;   //move old soldier 3 to prove he is still accessable under old name
   soldier[3].x -= 40;   //move old soldier 4 to prove he is still accessable under old name
   soldier[4].x -= 50;   //move old soldier 5 to prove he is still accessable under old name
   //
   //
   wait(-10);
   //flush and reset soldier array for next level.
   int i;   for(i=0; i<max_soldiers; i++)   { ent_remove(soldier[i]); }     //see - old soldiers DO die
   free(soldier);   //now as if it had never been used...
   //
   //
   //
   beep();
}
Any questions, fire away...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Dynamic variables/structs/entintys/etc names [Re: EvilSOB] #240210
12/09/08 23:53
12/09/08 23:53
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
Removal of elements may leave free slots that can be reused.
A linked listed can be used to manage free slot indices, so that the first available free slot index is found easily and quickly.

Also a hash map/table plug-in was offered in Lite-C contributions, 'I' believe.

Re: Dynamic variables/structs/entintys/etc names [Re: testDummy] #240215
12/10/08 01:03
12/10/08 01:03
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
True, my above code it a teaching example of a simple but "dirty" extendable array,
rather than learning the whole linked lists concept.

Linked lists IS the preferred way to go though, just a steeper learning curve.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Dynamic variables/structs/entintys/etc names [Re: EvilSOB] #240253
12/10/08 08:40
12/10/08 08:40
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline
Expert
Espér  Offline
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
I don't think he will use more than 999999999 ents on one map...
So why not setting the array on that count at start?


Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: Dynamic variables/structs/entintys/etc names [Re: Espér] #240290
12/10/08 12:08
12/10/08 12:08
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
that'll eat insane memory.

linked lists ftw! sorry can't say more... gotta run!

julz


Formerly known as JulzMighty.
I made KarBOOM!
Re: Dynamic variables/structs/entintys/etc names [Re: JibbSmart] #240423
12/10/08 21:23
12/10/08 21:23
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
That depends on the purpose. In some cases array lists are to be preferred.


Always learn from history, to be sure you make the same mistakes again...
Re: Dynamic variables/structs/entintys/etc names [Re: EvilSOB] #241249
12/15/08 02:27
12/15/08 02:27
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
Thanks for that example! That is more like what im trying to do.
I have found a tutorial on linked lists and will start to learn that also as was sugested.
Thanks to all


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
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