Gamestudio Links
Zorro Links
Newest Posts
Alpaca Plugin v1.5.2 Release
by kzhao. 01/11/26 13:42
Alpaca Plugin v1.4.0
by kzhao. 01/11/26 13:38
separating groups of 3 digits by a comma
by joe_kane. 01/11/26 00:01
MRC.c and WFO
by joe_kane. 01/10/26 23:58
BarOffset (default = 940 for daily bars?
by joe_kane. 01/10/26 23:46
NOMAX undeclared identifier.
by Petra. 01/09/26 21:12
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (Quad), 2,803 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
joe_kane, Namitha_NN, Syndrela, agasior, mosfet
19189 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
events in structs #354677
01/20/11 22:19
01/20/11 22:19
Joined: Apr 2009
Posts: 138
Germany
T
Toryno Offline OP
Member
Toryno  Offline OP
Member
T

Joined: Apr 2009
Posts: 138
Germany
Hi, is there any possibility to make struct including one or more events which can be used later by other functions? I tried with the following code and some similar code but this all didn't work.

Code:
void evt () {
	storage = 1;
}

typedef struct {
	var storage;
	EVENT evt;
	
} test_struct;


function main() {
	test_struct bla;
	bla.evt;
	printf("%f", bla.storage);
}



Last edited by Toryno; 01/21/11 04:44.

Thanks for reading, thinking, answering wink
Re: events in structs [Re: Toryno] #354701
01/21/11 07:32
01/21/11 07:32
Joined: Jan 2011
Posts: 120
United States
Logan Offline
Member
Logan  Offline
Member

Joined: Jan 2011
Posts: 120
United States
What sort of way is this code failing? I think the idea is getting confused because you've included EVENT evt; in the struct, and this is the same name as the void above... but by doing this, you haven't actually created any relationship between those two things, you've simply defined a function evt() which happens to have the same name as an element in test_struct. Better to define a function pointer within the struct, then explicitly set it TO evt(), then try to call it.

Code:
typedef struct {
...
void* event;
} test_struct;

...
// then later on, inside a function somewhere
test_struct bla;
bla.event = evt;
bla.event(); // this calls evt()




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