Gamestudio Links
Zorro Links
Newest Posts
contractUpdate() is filtering if >2 rows
by mistery. 12/04/26 19:03
Removing outliers from files
by AndrewAMD. 12/02/26 15:26
SGT_FW
by Aku_Aku. 11/30/26 08:19
Experiences with cTrader
by JeyKey II. 11/27/26 09:04
make a complaint
by EW_bytes. 11/26/26 23:00
FXCM => AVA Trade Plugin???
by Martin_HH. 11/25/26 21:59
No connection to MT4
by Martin_HH. 11/23/26 06:38
MinMax function on History t6 file
by LucasJoshua. 11/21/26 14:28
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
0 registered members (), 1,827 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EvanTJ, rht, MaliceTheMaker, Haitao_Ren, JimSimons
19250 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Struct array initialization (noob question) #153971
09/14/07 00:44
09/14/07 00:44
Joined: Sep 2007
Posts: 14
X
xykynan Offline OP
Newbie
xykynan  Offline OP
Newbie
X

Joined: Sep 2007
Posts: 14
I've just recently gotten into structs and arrays, and was wondering if there was a better or more organized way initialize struct arrays:

typedef struct
{
char name[10];
int bas_hp;
int bas_att;
int bas_def;
int bas_acc;
int bas_eva;
} JOB;

JOB job[5];

void job_init ()
{
(job[0]).name = "Thief";
(job[0]).bas_hp = 9;
(job[0]).bas_att = 4;
(job[0]).bas_def = 3;
(job[0]).bas_acc = 6;
(job[0]).bas_eva = 3;
}

Thanks in advance.

Re: Struct array initialization (noob question) [Re: xykynan] #153972
09/14/07 03:27
09/14/07 03:27
Joined: Oct 2006
Posts: 873
S
Shadow969 Offline
User
Shadow969  Offline
User
S

Joined: Oct 2006
Posts: 873
if i've understood you correct that's the code yo initialise all jobs in array

Code:
typedef struct
{
char name[10];
int bas_hp;
int bas_att;
int bas_def;
int bas_acc;
int bas_eva;
} JOB;

JOB job[500];

void job_init (JOB* jb)
{
jb.name = "Thief";
jb.bas_hp = 9;
jb.bas_att = 4;
jb.bas_def = 3;
jb.bas_acc = 6;
jb.bas_eva = 3;
}

void init_all_jobs()
{
var num = 0;
while(num<499)
{
job_init (job[num]);
num+=1;
}
}



Re: Struct array initialization (noob question) [Re: Shadow969] #153973
09/14/07 11:06
09/14/07 11:06
Joined: Sep 2007
Posts: 14
X
xykynan Offline OP
Newbie
xykynan  Offline OP
Newbie
X

Joined: Sep 2007
Posts: 14
Thanks for the reply, however my intention was to give each job[x] a different initial value. I was wondering if there was an easier way to assign values in structs rather than typing out (job[x]).var1 = ...;

Sorry I didn't make myself clear.

Re: Struct array initialization (noob question) [Re: xykynan] #153974
09/14/07 11:22
09/14/07 11:22
Joined: Oct 2006
Posts: 873
S
Shadow969 Offline
User
Shadow969  Offline
User
S

Joined: Oct 2006
Posts: 873
maybe that'll help you

void job_init (JOB* jb, char* name, var hp, var att, var def, var acc, var eva)
{
jb.name = name;
jb.bas_hp = hp;
jb.bas_att = att;
jb.bas_def = def;
jb.bas_acc = acc;
jb.bas_eva = eva;
}

initialisation and setting all parameters in one function

Re: Struct array initialization (noob question) [Re: Shadow969] #153975
09/15/07 00:18
09/15/07 00:18
Joined: Sep 2007
Posts: 14
X
xykynan Offline OP
Newbie
xykynan  Offline OP
Newbie
X

Joined: Sep 2007
Posts: 14
Thank you very much, this was just what I was looking for!


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