Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 17 Apr 2013
Offline Last Active Apr 24 2015 11:02 PM

#5145206 Expression must have class type?

Posted by on 07 April 2014 - 06:35 PM

Yes, clearly this:


fscanf(Map, "%d", &Map.tile[y][x]);


and this


&Map.tile[y][x] != 0


Are the problems. Could the OP please clarify exactly where the map data is supposed to be being stored? There seems nothing in the Sprite class to store this info, perhaps Map is a global variable? If so, you are shadowing it with the local Map in the load method. But I can't think of any implementation of the global that would make the syntax as posted meaningful.


[On another note] There is no point putting those #define's inside the class like that. They won't be contained in the class namespace. You'd be far better to use static const members, but I'm not sure why these are being defined inside a Sprite class since they relate to the map anyway. There is some confusion going on here with naming of things I think.

Sorry to everyone wondering where the it's actually throwing the error, I posted this before I went to bed and kinda spaced it. Both of those lines are throwing the error. I'm not to confident on using #defines, as Im not very familiar with them, so if there is a better way to achieve my goal, i'm more than open to suggestions/ideas or tuts.  No map is not a global variable. This is being done in the sprite class because I didn't want to create any unnecessary classes. 

#5144884 Expression must have class type?

Posted by on 06 April 2014 - 09:37 PM

Im working on Tile Mapping using SDL2, and so far stuff was going good, but for the life of me I can't figure out what I need to do to solve this problem.

This is the error: Expression must have class type.

Here is the class along with its' header.

#include "Sprite.h"
#include "includes.h"

CSprite::CSprite(SDL_Renderer *passedrenderer, std::string Filepath, int x, int y, int w, int h)

	renderer = passedrenderer;
	image = IMG_LoadTexture(renderer, Filepath.c_str());
	std::cout<<"after " << image<<std::endl;

	rect.x = x;
	rect.y = y;
	rect.w = w;
	rect.h = h;



void CSprite::Draw()
	SDL_RenderCopy(renderer, image, NULL, &rect);
void CSprite::SetX(int X)
	rect.x = X;
void CSprite::SetY(int Y)
	rect.y = Y;
void CSprite::SetPosition(int X, int Y)
	rect.x = X;
	rect.y = Y;

int CSprite::GetX()
	return rect.x;
int CSprite::GetY()
	return rect.y;
void CSprite::LoadMap(char *name)
	int x, y;
	FILE *Map;
	Map = fopen(name, "rb");

	for (y = 0; y < MAP_MAX_Y;y++)
		for (x = 0; x < MAP_MAX_X;x++)
			fscanf(Map, "%d", &Map.tile[y][x]);
void CSprite::DrawMap()
	int x, y;

	for (y = 0; y < MAP_MAX_Y; y++)
		for (x = 0; x < MAP_MAX_X; x++)
			if (&Map.tile[y][x] != 0)



#pragma once
#include "includes.h"
class CSprite
	CSprite(SDL_Renderer *passedrenderer,std::string Filepath, int x, int y, int w, int h);

	void SetX(int X);
	void SetY(int Y);
	void SetPosition(int X, int Y);
	void Draw();
	void LoadMap(char *name);
	int GetX();
	int GetY();
	void DrawMap();
    #define	MAP_MAX_Y 10;
    #define MAP_MAX_X 10;
    #define TILE_SIZE 32;
	SDL_Texture *image;
	SDL_Rect rect;
	SDL_Renderer *renderer;


Thanks for any help, I'm going to attempt to solve this again tomorrow, but I've been a bit crushed on time recently.

#5137904 Branching paths.

Posted by on 10 March 2014 - 02:07 PM

Since we don't know any specifics about your game, or the types of things you're wanting to change based on player decisions, it's tough to give more specific advice.


I'll come up with an example that will hopefully help you wrap your head around the general concept. If not, give us some specifics about your game, the decisions, and the repercussions.


Let's say there's a town that's having trouble with goblins in a nearby forest. And the player has to decide whether to help or not. The problems start out with caravans being hit which increases prices in this town 10%. And there will be goblin random encounters when in the "nearby forest" area so long as this problem exists.


You're correct to think that there is a better way instead of one mega-if-else-switch statement. Though technically doable, it would quickly become a nightmare to maintain. 


Let's come up with a few classes for this.

StoryEventNode - Something that happens in our game.

Transition - A way to get from one StoryEventNode to the next. Could be a dialog choice, a quest completion, a quest failiure, an npc death, time delay, etc.

Consequence  - Something that affects the game world.


So in our story graph, we're at the StoryEventNode (Goblins near Arcadia). It has a list of Consequences in it, so we apply those Consequence to the game world when we "visit" the node. Arcadia.MerchantPriceModifier += 10%, and the area HauntedWoods needs to add goblins to its random encounter table.


There are two main options here. The player helps, or the player doesn't. There can be a Transition here tied to GoblinKing_01's death. Killing the king kills off the goblin presence here. Prices go back to normal, and you stop finding them on your random encounter table of the HauntedWoods. On the other side of things, if the GoblinKing_01 is still alive for a week's time, the problem worsens. A nearby fishing village is burned to the ground, the goblins get tougher, and start showing up in a nearby dungeon's random encounter table.


Those "Transitions" (or triggers, or decisions) would hook into our game logic as a listener. And once they happened, we'd go to the next StoryEventNode on our list. If the player goes out and kills GoblinKing_01, we visit our (Goblins removed from Arcadia) StoryEventNode and apply its consequences (the prices return back to normal, and we take our Goblin random encounter(s) out of the HauntedWoods.  If the player dilly-dallies for a week, we Transition to the corresponding StoryEventNode (Goblins overrun BubblingSprings) and apply its consequences, we destroy the fishing village and every NPC in it, level up our goblins, add "fish" to their random loot table, and put some Goblin random encounter(s) in the nearby dungeon area.


You need to take a little bit of time to see what you'd like to be dynamic in your game world. In this example, I wanted to affect town prices and random encounters. So my Town class would need a variable like merchantPriceModifier. And my RandomEncounterTable class would need to expose a way to change the table out entirely or add more entries to it. In this way, we have data driven these features and it's only a matter of adjusting the data when visiting our StoryEventNodes.


I hope this helps clear things up a bit. If not, give us some specific details about your game, and maybe we can get a little more specific with an answer. smile.png


- Eck

Think of my game kinda like persona where you have different social links, and you can either accept peoples invites to go do stuff, or you can not, but if you do accept an invite, you have to spend the entire time with them, and you miss out on everything else. This is what I want to achieve, However I want this to affect events that are avaliable in the future as well. also if I havn't said so already, I'm writing in C++.

#5137593 Branching paths.

Posted by on 09 March 2014 - 01:17 PM

Nicely said haegarr. 


Bigfatmeany, have a look at this quest system thread for a few more design ideas:



- Eck

Thanks for this, this gave me some insight, and amazingly enough is applying more than I would though, I guess I could count these events as quests, and make them randomly generated if I find it necessary, or it seems stale to play more than once, as I will need some replay-ability to get my overall goal across.

#5131913 Where do I go next?

Posted by on 16 February 2014 - 09:52 PM

Make something! A beginners' book is a good way to get you off the ground, but now you'll learn much more by doing. If you need ideas for projects, tell us what you have already made and what kinds of things you are interested in.

well, http://www.gamedev.net/page/resources/_/technical/game-programming/your-first-step-to-game-development-starts-here-r2976, I know for a fact that I can complete this in SDL, however I am unsure about doing stuff in other languages. I mean, games have always been there for me, and they have helped me through some tuff times, so I really want to pay back to the community what I got out of it. And i have no desire for anything 3D, that's just not what Im into, other than that I havn't really expressed myself to far out off the books.

#5131898 Where do I go next?

Posted by on 16 February 2014 - 08:50 PM

After reading Beginning C++ through game programming, by Michael Dawson, and then taking a summer workshop for intro into 2D game design, and jumping into, and out of SDL in a couple weeks,after a few months(i.e last week), I decided to pick up Beginning game programming by, Jonathan Harbour. Im wondering where I should take my learning next. What should I advance to after I finish this book?