Ah, thanks. I misunderstood the concept of static then.
Any suggestions for what I might use to achieve my goal?
-snip-
A static global variable is private to a .cpp file. You can declare it as
[cpp]
extern unsigned char Error;
[/cpp]
in the header and define it
[cpp]
unsigned char Error = 0;
[/cpp]
in ScriptCom.cpp
Awesome, works like a charm. Thanks!
Having some problems with C++. Coming from C#, I fuck up most of the syntax. Here's my code so far.
[b]Main.cpp[/b]
[cpp]#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "WinterEscape");
sf::Image Tex(32, 32, sf::Color::White);
Entity Ent;
Ent.Sprite::SetImage(Tex);
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear(sf::Color(40, 70, 125));
Ent.Draw(App);
App.Display();
}
return EXIT_SUCCESS;
}[/cpp]
[b]Entities/Entity.cpp[/b]
[cpp]#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
class Entity
{
public:
sf::Sprite Sprite;
Entity()
{
Sprite = sf::Sprite();
}
~Entity()
{
}
void Draw(sf::RenderWindow App)
{
App.Draw(Sprite);
}
};[/cpp]
It whines about not being able to find the class name "Entity", so apparently it doesn't read the Entity.cpp file. How do I fix this?
[editline]24th December 2010[/editline]
[cpp]#include "Entities/Entity.cpp"[/cpp]
Says:
[quote]Cannot open include file: 'Entities/Entity.cpp': No such file or directory[/quote]
You don't include .cpp files from other .cpp files. Put the class definition in a header file (e.g. Entity.hpp) and include that. The implementation of the class's methods goes in Entity.cpp.
Syntactically that #include looks right, though. If it can't find the file then it's something with the paths in your project. Where is that Entities directory located?
[QUOTE=Chris220;26927250]You have to compile sfml-system first on all four build targets.[/QUOTE]
Thanks but I found out that when I compiled sfml-system, it had named it libsfml-system-d.dll.a so i just removed the .dll part so that it could find it. Thanks anyways Chris :)
[QUOTE=Wyzard;26932113]You don't include .cpp files from other .cpp files. Put the class definition in a header file (e.g. Entity.hpp) and include that. The implementation of the class's methods goes in Entity.cpp.
Syntactically that #include looks right, though. If it can't find the file then it's something with the paths in your project. Where is that Entities directory located?[/QUOTE]
Nevermind, I rewrote the whole project using headers and now it all works :buddy: Thanks!
[QUOTE=awfa3;26933241]Thanks but I found out that when I compiled sfml-system, it had named it libsfml-system-d.dll.a so i just removed the .dll part so that it could find it. Thanks anyways Chris :)[/QUOTE]
I wonder why it did that... how strange! Ah well, glad to hear it's working.
Yea it was pretty confusing
Since I'm absolute shit with C++, I can't figure out why [url=http://pastie.org/private/8vqpfvepggo0oupnn2ww]this[/url] code crashes when the function ends and the runtime calls the destructor of the Elements vector. Stack trace:
[img]http://imgur.com/tUj6V.png[/img]
What am I doing wrong?
(also, yes, the code is messy and needs some stupid little optimizations like not calling .size() every time. But right now I just want to get it to work.)
What's the crash message?
And why are you allocating Elements.size() / 3 GLuints, but stuff in Elements.size() elements?
Instead of using an index to go through each index, you could also use an iterator for the m_* vectors.
And even more efficient: a std::memcpy for the Elements-vector (since it's a POD type).
Also be careful when passing a this-pointer to other functions from the constructor.
[QUOTE=ZeekyHBomb;26939039]What's the crash message?[/QUOTE]
Breakpoint encountered at HeapFree in _free_base @free.c.
[QUOTE=ZeekyHBomb;26939039]And why are you allocating Elements.size() / 3 GLuints, but stuff in Elements.size() elements?[/QUOTE]
Because I'm a fucking retard? It doesn't crash anymore now - I guess I just overflowed the heap like hell.
[QUOTE=ZeekyHBomb;26939039]Instead of using an index to go through each index, you could also use an iterator for the m_* vectors.[/QUOTE]
Oh, I didn't know about that.
[QUOTE=ZeekyHBomb;26939039]And even more efficient: a std::memcpy for the Elements-vector (since it's a POD type).[/QUOTE]
Oh, that is awesome, I had no idea. I guess I really need to read up more about the STL.
Anyhow, fixed. Thanks a bunch!
Why can't I compare the getf() values? lowestfscore somehow always wins, even though no value is above 255.
[cpp]ctile * lowestfscore = new ctile;
lowestfscore->set(255, 255);
for(std::list<ctile *>::iterator i = openlist.begin(); i != openlist.end(); i++)
if((*i)->getf() < lowestfscore->getf())
lowestfscore = *i;
[/cpp]
Strip down your code to a barebone testcase and post that; there's not enough information in your currently posted code.
[QUOTE=ZeekyHBomb;26940255]Strip down your code to a barebone testcase and post that; there's not enough information in your currently posted code.[/QUOTE]
Who me?
Yes.
[editline]25th December 2010[/editline]
And I mean a testcase that I can compile without modifications; shouldn't really take long to code...
[QUOTE=ZeekyHBomb;26940532]Yes.
[editline]25th December 2010[/editline]
And I mean a testcase that I can compile without modifications; shouldn't really take long to code...[/QUOTE]
I recreated it but it works now. Guess I'll debug my current code.
[editline]24th December 2010[/editline]
Ok here is the code in it's entirety. I have no idea how to fix it. [url]http://pastebin.com/EUdNktTs[/url]
If anybody can read that, I'll be damned.
[QUOTE=Jookia;26944317]If anybody can read that, I'll be damned.[/QUOTE]
I thought I formated it well :saddowns:
[QUOTE=WTF Nuke;26941083]I recreated it but it works now. Guess I'll debug my current code.
[editline]24th December 2010[/editline]
Ok here is the code in it's entirety. I have no idea how to fix it. [url]http://pastebin.com/EUdNktTs[/url][/QUOTE]
Well documented code I see...
Well, it's far from barebone and also not compilable without additional code and guesswork on that.
[QUOTE=WTF Nuke;26941083]I recreated it but it works now. Guess I'll debug my current code.
[editline]24th December 2010[/editline]
Ok here is the code in it's entirety. I have no idea how to fix it. [url]http://pastebin.com/EUdNktTs[/url][/QUOTE]
A few comments scattered around would make that a lot easier to understand
[QUOTE=Darwin226;26950662]glVertexPointer is deprecated, why are you using it?[/QUOTE]
Don't get on my case about deprecated code.
How do I get the inverse of ^z$ in regex so that it would match everything else than ^z$ ?
Yeah sorry about that, I coded that when I was tired. Bad idea. Anyway I'll make a standalone version with better documentation, just give me a bit.
Edit: Ok it's x-mas and I'm lazy. Will get it done tomorrow.
[QUOTE=DevBug;26954156]Don't get on my case about deprecated code.[/QUOTE]
It's ok if you can't handle it XD
[QUOTE=Darwin226;26950662]glVertexPointer is deprecated, why are you using it?[/QUOTE]
Because Khronos seems to have fun deprecating everything from version to version, so people stop giving a fuck if method x is deprecated, and they're right.
Sorry, you need to Log In to post a reply to this thread.