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
0 registered members (), 18,561 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
accessing struct elements in an array #404064
07/02/12 03:10
07/02/12 03:10
Joined: Nov 2011
Posts: 21
MO:US and sometimes Ambato Ecu...
L
LewyT Offline OP
Newbie
LewyT  Offline OP
Newbie
L

Joined: Nov 2011
Posts: 21
MO:US and sometimes Ambato Ecu...
Ok, I think I have done my due diligence and searched the forums but I can't figure out what I'm doing wrong here.
Basically I'm trying to make an array of struct instances and then edit and access the elements of those structs.

Code:
typedef struct SKILL{
	
	STRING* NAME;
	STRING* DESC;
	BMAP* ICON;
	var LEVEL;
	var PREQ;
	var BUY;
	STRING* UPGRADE;
	var XTREE;
	var YTREE;

} SKILL;

var skillnum = 1;
SKILL skilltree[50] ;
//skilltree = malloc(totalskills*sizeof(SKILL));
//memset( skilltree[1], 0, sizeof(SKILL));

skilltree[1].NAME = str_create("REST");
//skilltree[1].ICON = str_create("icons\\REST.png");
skilltree[1].ICON = bmap_create("icons\\REST.png");
//skilltree[1].ICON = bmap_createpart("icons\\REST.png",0,0,100,100);
skilltree[1].DESC = str_create("");
skilltree[1].LEVEL = 1;
skilltree[1].PREQ = 0;
skilltree[1].BUY = 1;
skilltree[1].UPGRADE= str_create("+2");
skilltree[1].XTREE = 5;
skilltree[1].YTREE = 3;


function MakeSkillTree()
{
	BMAP* tempicon;
	var b=1;
	var *xpos,*ypos;
	//STRING* fname = "test";
	//sys_marker = "FNM";
	//fname = skilltree[1].ICON;
	//fname = str_create(skilltree[b].ICON);
	
	//TXTMESSAGE = "Hello World"; 
	//pan_setstring(panDisplay, 8, 5,90, arial_font, str_create(TXTMESSAGE) );
	//wait(1);
	//pan_setstring(panDisplay, 8, 5,90, arial_font, str_create(fname) );
	
	/*
	for( b=1; skilltree[b].LEVEL>=0; b+=1 );
	{*/
		//mesg = "Hello World"; 
		//mesg = skilltree[b].ICON;
		//fname = skilltree[b].ICON;
		//tempicon = bmap_create( fname );
		tempicon = skilltree[b].ICON;
		//tempicon = bmpLIFELEVEL;
		//tempicon = bmap_create("icons\\REST.png");
		//tempicon = bmap_create( skilltree[b].ICON );
		//skillicons[b] = bmap_create( skilltree[b].ICON );
		//sys_marker = "BUT";
		
		xpos = (skilltree[b].XTREE)*100;
		ypos = (skilltree[b].YTREE)*100;
		
		//pan_setbutton(panSkillTree, 0,   0,    xpos, ypos, skillicons[b], skillicons[b], skillicons[b], skillicons[b],     NULL,                NULL,                NULL);

		pan_setbutton(panSkillTree, 0,   0,    xpos, ypos, tempicon, tempicon, tempicon, NULL,  NULL,   NULL,  NULL);

		//pan_setbutton(panSkillTree, 0,0, 50,300, bmpLIFELEVEL , bmpLIFELEVEL, bmpLIFELEVEL, NULL, NULL, NULL, NULL);  // this line for reference only
	//}
//    pan_setbutton(PANEL*,       num, type, x,    y,                   BMAP* bmapOn,  BMAP* bmapOff, BMAP* bmapOver, BMAP* bmapOverOff, void* functionClick, void* functionLeave, void* functionOver);
	//*/
}



I get an "invalid function arguments" error
I've left all the commented lines because they were things I tried.
Sometimes I could get a script error instead.
It seems none of the info I've stored in the struct is accessible later.

please help, I've been banging my head against this for days and I'm sure it is a simple error I just can't see.

Re: accessing struct elements in an array [Re: LewyT] #404065
07/02/12 05:42
07/02/12 05:42
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
Hi,

Where the following portion of code is located ?
Code:
//skilltree = malloc(totalskills*sizeof(SKILL));
//memset( skilltree[1], 0, sizeof(SKILL));

skilltree[1].NAME = str_create("REST");
//skilltree[1].ICON = str_create("icons\\REST.png");
skilltree[1].ICON = bmap_create("icons\\REST.png");
//skilltree[1].ICON = bmap_createpart("icons\\REST.png",0,0,100,100);
skilltree[1].DESC = str_create("");
skilltree[1].LEVEL = 1;
skilltree[1].PREQ = 0;
skilltree[1].BUY = 1;
skilltree[1].UPGRADE= str_create("+2");
skilltree[1].XTREE = 5;
skilltree[1].YTREE = 3;



If it outside a function then : you can't initialize variables using function calling if it is outside a function. Put the initialization code into a function and call it in the main function, or use a startup (..._startup).

Best regards.

Re: accessing struct elements in an array [Re: 3dgs_snake] #404131
07/03/12 02:44
07/03/12 02:44
Joined: Nov 2011
Posts: 21
MO:US and sometimes Ambato Ecu...
L
LewyT Offline OP
Newbie
LewyT  Offline OP
Newbie
L

Joined: Nov 2011
Posts: 21
MO:US and sometimes Ambato Ecu...
thanks, that was the problem.
I'm not used to C but I'll get it eventually.


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