Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Akow, tomaslolo), 1,536 guests, and 12 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 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 | 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