Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, juanex, Grant), 1,018 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Self declared structs as param #414119
12/23/12 15:12
12/23/12 15:12
Joined: Jan 2011
Posts: 40
ChriZ Offline OP
Newbie
ChriZ  Offline OP
Newbie

Joined: Jan 2011
Posts: 40
Hey it's me again. Sorry for asking you so much stuff, but this time I got no clue, how to solve my problem.
Please have a look at the following code:

Code:
#include <acknex.h>

#define dirt 0
#define grass 1
#define stone 2
#define wood 3

struct BLOCK
{
	ENTITY* e;
	int t;
	int dmg;
};

function getSkin(BLOCK* b)
{
	if(!b) return "";
	switch(b->t)
	{
		case dirt:
		  return "texture_dirt.bmp";
		case grass:
		  return "texture_grass.bmp";
		case stone:
		  return "texture_stone.bmp";
		case wood:
		  return "texture_wood.bmp";
		case default:
		  return "texture_error.bmp";
		
	}
}


In general very simple and I excpected it to be able to be compiled without any problems. But that's not the case! Insted of this I get the message, that there would be a syntax error with the "getSkin(..)" function and I don't know why. At first I thought that the missing prototype of the function is the reason for the error bu it isn't. I think Lite-C cannot recognize the type of the parameter.
So I ask you to help me and to tell me what's wrong with the implentation of the function.

Sorry for my messy english ^^
Greetings,
Chris


.:Mit freundlichen Grüßen, Chris:.
Re: Self declared structs as param [Re: ChriZ] #414120
12/23/12 15:21
12/23/12 15:21
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline
Member
krial057  Offline
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
You need to pass it with the struct keyword:
getSkin(struct BLOCK* b)

This should work(you also had case default. It's just default):
Code:
char* getSkin(struct BLOCK* b)
{
	if(!b) return "";
	switch(b->t)
	{
		case dirt:
		  return "texture_dirt.bmp";
		case grass:
		  return "texture_grass.bmp";
		case stone:
		  return "texture_stone.bmp";
		case wood:
		  return "texture_wood.bmp";
		default:
		  return "texture_error.bmp";
		
	}
}



If you don't want to always pass the struct keyword, typedef the Block(recommanded):
Code:
typedef struct BLOCK
{
	ENTITY* e;
	int t;
	int dmg;
} BLOCK;

char* getSkin(BLOCK* b)
{
  ...
}


Re: Self declared structs as param [Re: krial057] #414122
12/23/12 15:32
12/23/12 15:32
Joined: Jan 2011
Posts: 40
ChriZ Offline OP
Newbie
ChriZ  Offline OP
Newbie

Joined: Jan 2011
Posts: 40
Well, thanks. A few seconds ago I also noticed this. I totally forgot that C Sntax requires this ... In this point C++ is a little bit more comfortable :-)

Chris


.:Mit freundlichen Grüßen, Chris:.

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