Gamestudio Links
Zorro Links
Newest Posts
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Trading Journey
by 7th_zorro. 04/27/24 04:42
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 780 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 3
Page 2 of 4 1 2 3 4
Re: 'Structured' programming in Lite-C [Re: PigHunter] #277573
07/09/09 17:05
07/09/09 17:05
Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
GorNaKosh Offline
Junior Member
GorNaKosh  Offline
Junior Member

Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
I was trying to deal with add_struct and game_save/game_load the whole day long, but I don't get it work!
One Problem is, that when you use the game_load function, there musst exists the same count of initialized structs in the script like when you saved the game. And also I have no idea where the pointer of the saved memory area are after game_load ...

I'm really confused an frustrated about that save management!

Re: 'Structured' programming in Lite-C [Re: GorNaKosh] #278936
07/16/09 08:58
07/16/09 08:58
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
I have a question about allocate Memory with: malloc(sizeof(STRUCT));

Code:
typedef struct
{
	var    koor_x_abs;
	var    koor_y_abs;
	var    koor_x;
	var    koor_y;
	var    bombenreichweite;
	var    erzeuger_id;
	var    kicker_id;
	var    speed;
	PANEL* panel;
} BOMBE;



typedef struct
{
	var    koor_x_abs;
	var    koor_y_abs;
	var    koor_x;
	var    koor_y;
	var    start_koor_x;
	var    start_koor_y;
	var    anz_leben;
	var    unverwundbar;
	var    richtung;
	var    bombenanzahl;
	var    bombenanzahl_max;
	var    bombenreichweite;
	var    speed;
	var    speed_orginal;
	var    anz_schuhe;
	var    tod;
	var    id;
	var    ki;
	var    sp_status;
	var    negativ;
	
	var    r;
	var    l;
	var    u;
	var    o;
	
	var    t1;
	var    t2;
	
	var    joy1_aktiv;
	var    joy2_aktiv;
	
	var    t1_gedr;
	var    t2_gedr;
	
	PANEL* panel;
	
	BOMBE  Bombe[Anz_bomben];
} PLAYER;

PLAYER  Player[Anz_spieler];



You can see i want to use a array from the Struct (Anz_spieler = 8).
How do i use now malloc?

Player = malloc(sizeof(PLAYER)); --> is this right?

Re: 'Structured' programming in Lite-C [Re: Widi] #278966
07/16/09 09:59
07/16/09 09:59
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline OP
Expert
Joozey  Offline OP
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
You can create dynamic arrays this way:

Code:
PLAYER *player = malloc( sizeof( PLAYER ) * Anz_spieler );



A multidimensional array would go like:
Code:
PLAYER **player = malloc( sizeof( PLAYER* ) * players_y );

for( i=0; i<players_x; i++ ) {
  player[i] = malloc( sizeof( PLAYER ) );
}




Click and join the 3dgs irc community!
Room: #3dgs
Re: 'Structured' programming in Lite-C [Re: Joozey] #278970
07/16/09 10:15
07/16/09 10:15
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
Thanks a lot, will go test it...

Re: 'Structured' programming in Lite-C [Re: Widi] #280749
07/24/09 03:08
07/24/09 03:08
Joined: Apr 2009
Posts: 39
T
TrQuocAn Offline
Newbie
TrQuocAn  Offline
Newbie
T

Joined: Apr 2009
Posts: 39
excuseme !

But can we use the Array without malloc function ??

for ex :

Code:
PLAYER  Player[Anz_spieler];
// Not use the malloc here because Player is a array not pointer !
Player[1].r = 2;
Player[3].u = 3;
....



Re: 'Structured' programming in Lite-C [Re: TrQuocAn] #280796
07/24/09 09:19
07/24/09 09:19
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
I think so, but "Anz_spieler" cannot be a variable, it must be an
actual number, or a '#define'ed constant number.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: 'Structured' programming in Lite-C [Re: EvilSOB] #280875
07/24/09 13:48
07/24/09 13:48
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
Funny, I thought of pretty much the same method (creating create_ and remove_ functions for all structs) the other day. Good to know someone has tested it!

Joozey, what's the " ** " in your last post? I've never seen that... what does it mean?


~"I never let school interfere with my education"~
-Mark Twain
Re: 'Structured' programming in Lite-C [Re: Germanunkol] #280876
07/24/09 13:57
07/24/09 13:57
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Pointer to a pointer. (The start of an array of of pointers)
Cause the ENTITYs in the array are really only a pointer to an object, you need an array of pointers.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: 'Structured' programming in Lite-C [Re: EvilSOB] #281025
07/25/09 01:21
07/25/09 01:21
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline OP
Expert
Joozey  Offline OP
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Quote:
Funny, I thought of pretty much the same method (creating create_ and remove_ functions for all structs) the other day. Good to know someone has tested it!

And good to know someone else has got the same idea ^^ must be some use in this way of programming then! grin.

Quote:
Joozey, what's the " ** " in your last post? I've never seen that... what does it mean?


As evil says.

*A = [0][1][2][3][4][5][6] //array, where pointer A points to [0]
**B = [A[0]][A[0]][A[0]] //array where pointer A points to [p[0]]

A is a normal array with 6 indexes containing some value.
B is a normal array with 3 indexes, but each containing a pointer to array A. Doesn't need to be the same array, just a new array of type A.

So, B is a pointer to an array containing pointers to an array. Hence the two asteriskes. The compiler will puke with only one asterisk.


Click and join the 3dgs irc community!
Room: #3dgs
Re: 'Structured' programming in Lite-C [Re: Joozey] #281247
07/26/09 12:39
07/26/09 12:39
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Joozey, you're explanations are very appreciated!
I have an additional question though, hope you don't mind.
I'm still thinking in ways of c-script how to solve a certain task.
I read your codes and explanations the third time, and I think my problem is that I think more 'material', as you might know or not, I programed a fish game where the player collects fishes in a swarm to keep an evil fish in a safe distance.
This 'collecting' might be similar to that of an inventory.
At the beginning of a level, I place the fishes in the level, the swarm gets an array to save the handle of each fish that has been collected while the fish saves in a skill the number of its place in the array, and when the fish leaves the swarm, because it dies or it flees because the evil fish comes to near to it, it resets it place in the array to zero, and its skill as well.

What advantage has a struct as you use it in your example to the way that I just described?

Page 2 of 4 1 2 3 4

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