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
1 registered members (TipmyPip), 18,618 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
Initializing Panels with variables doesn't work #423630
06/02/13 12:53
06/02/13 12:53
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline OP
Member
krial057  Offline OP
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
Hello,

I think it is not possible to use variables in Panel struct initializations:

Code:
var test = 2;

typedef struct Custom_Panel{ 
  var test_x; 
} Custom_Panel; 

Custom_Panel* mypan = { test_x = test;}
VECTOR* testVec     = {x = test;}
PANEL* looptxt_pan  = { pos_x  = test;}



I get a "number syntax test" error for the line "PANEL* looptxt_pan = { pos_x = test;}"
However, the variable initialization works for Vector and custom structs(didn't try it with other engine objects yet)

The manual says:
Quote:
Within the struct initialization, any numbers, variables, character strings, or pointers to other structs can be used, but internal engine variables (such as "camera"), and #defines (such as a previously defined "NUMBER_OF_ARRAY_ELEMENTS") can not be used.

But I couldn't find anything that it isn't working with Panels.

Last edited by krial057; 06/02/13 18:35.
Re: Initializing Panels with variables doesn't work [Re: krial057] #423678
06/03/13 07:12
06/03/13 07:12
Joined: Jul 2000
Posts: 28,024
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,024
Frankfurt
A struct can have variables, but you can not initialize variables with other variables. In the manual under "Variables" you can see how to initialize variables.

Re: Initializing Panels with variables doesn't work [Re: jcl] #423698
06/03/13 14:06
06/03/13 14:06
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline OP
Member
krial057  Offline OP
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
Quote:
but you can not initialize variables with other variables.

As far as I unterstand the manual, you can in a struct initialization. It says:
Quote:
Within the struct initialization, any numbers, variables, character strings, or pointers to other structs can be used


I also tested it with the Vector struct and it works:

Code:
#include <acknex.h>
var test = 42;
VECTOR* testVec = {x = test;}

function main()
{
	printf("%i", (int)testVec.x);
}



As i said in the original post, it's just not working for Panels...

Last edited by krial057; 06/03/13 14:07.
Re: Initializing Panels with variables doesn't work [Re: krial057] #423702
06/03/13 14:47
06/03/13 14:47
Joined: Jul 2000
Posts: 28,024
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,024
Frankfurt
It is indeed working in your example, due to the method how structs are generated, but this is not the 'official' way. In C, variables can only be initialized with constants, not with other variables. You need a function for setting panel variables dynamically from the content of other variables.

Re: Initializing Panels with variables doesn't work [Re: jcl] #423703
06/03/13 15:47
06/03/13 15:47
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline OP
Member
krial057  Offline OP
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
Ok, thank you very much. Maybe change this sentence in the manual then:
Quote:
Within the struct initialization, any numbers, variables, character strings, or pointers to other structs can be used


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