• What do you need help with? Version 5
    5,752 replies, posted
What IS wrong with it? Compiler error? Not working the way you want it to?
[QUOTE=Meatpuppet;39500267]Can anyone tell me what's wrong with this SFML and C++ function to highlight the outline of a rectangle around a text object? [cpp]void Menu::MenuItem::highlightRectOutline(sf::RenderWindow &window, Text text, sf::Color color) { sf::RectangleShape outlineRect; sf::Vector2f size(text.getWidth(), text.getHeight()); outlineRect.setSize(size); outlineRect.setPosition(text.getPosition()); outlineRect.setFillColor(sf::Color::Transparent); outlineRect.setOutlineColor(color); outlineRect.setOutlineThickness(5); window.draw(outlineRect); }[/cpp] Thanks.[/QUOTE] It's very hard to read minds over the internet. What did you do? What did you expect happen? What actually happened?
Wild guess, I bet it has something to do with your parameters; [cpp]Menu::MenuItem::highlightRectOutline(sf::RenderWindow &window, const Text& text, const sf::Color& color)[/cpp] [editline]6th February 2013[/editline] Or, I guess it wouldn't, because you're not changing anything. Still, I would have Text and sf::Color as references.
It's just not doing anything, that's what's wrong. [editline]7th February 2013[/editline] I changed them to references, still doesn't show up. What do you mean by not changing anything? [editline]7th February 2013[/editline] The "highlighting button" text appears, so I know the function is at least executing... this is where I implement it by the way [cpp]Menu::MenuResult Menu::handleButtonHover(sf::RenderWindow &window, float x, float y) { sf::Color color(255, 122, 40); std::list<MenuItem>::iterator it; for(it = menuItems.begin(); it != menuItems.end(); it++) { sf::FloatRect menuItemRect = it->buttonrect; if( menuItemRect.contains(x, y)) { printf("highlighting button...\n"); it->highlightRectOutline(window, it->text, color); } } return Nothing; [/cpp] MenuItem is just a piece of clickable text and MenuResult is what the result of the press is (in this case, nothing, because nothing is being pressed). [url]https://github.com/Tetramputechture/Yttra[/url]
Are you drawing then clearing the screen? That might be causing it, but I don't remember how sfml works.
Why don't you debug through it and see what could be causing it?
[QUOTE=Meatpuppet;39501237]It's just not doing anything, that's what's wrong. [editline]7th February 2013[/editline] I changed them to references, still doesn't show up. What do you mean by not changing anything? [editline]7th February 2013[/editline] The "highlighting button" text appears, so I know the function is at least executing... this is where I implement it by the way MenuItem is just a piece of clickable text and MenuResult is what the result of the press is (in this case, nothing, because nothing is being pressed). [url]https://github.com/Tetramputechture/Yttra[/url][/QUOTE] It's kind of hard to follow your program's flow, but it looks to me like you aren't clearing/drawing the window properly. In most cases, in each frame you should clear, draw everything, then display. Basically your draw calls shouldn't be inside highlightRectOutline and such, they should be in showMMenu.
[QUOTE=mobrockers2;39494958]Why are you not just doing [cpp] while stats != 0: print "You have %d points left over." % stats print "You have %d Body and %d Mind." % (body, mind) print "You must spend all your points!" print "How much do you wish to put into Body?" temp = int(raw_input("> ")) body += temp stats -= temp if ((body <= 3 and body >= 0) and stats >= 0): print "You have %d points in Body!" % body else: stats += temp body -= temp print "That's invalid." print "How much do you wish to put into Mind?" temp = int(raw_input("> ")) mind += temp stats -= temp if ((mind <= 3 and mind >= 0) and stats >= 0): print "You have %d points in Mind!" % mind else: stats += temp mind -= temp print "That's invalid." [/cpp] This should do it no? Kind of, I haven't really looked if it breaks anything.[/QUOTE] Eh, kind of. After fixing the indenting errors, it doesn't really do [I]quite[/I] what I want. It adds stats without checking them first, leading to the ability to exploit it to get more points than you should have, and it prompts you for Mind points even if your stats finally hits 0. [editline]6th February 2013[/editline] [QUOTE=eternalflamez;39494740]Well I don't know about Python but usually you could use "break", as such: [code] int x = 0; while(true) { print "I'll keep doing this" x++; if(x == 100) { break; } } [/code] or [code] for(int i = 0; i < 10; i++) { //When i = 8, stop the loop. if(i==8) { break; } } [/code][/QUOTE] This helps, thanks!
nevermind - sorted
Most likely. I made a php script that used µ for a unit, and it'd add a special character (fairly similar to those, I think) before the µ (though it'd still output it), but when I used it in the actual app, all was back to normal. Do you have the original string?
i need help with good program design, when making games specifically. this is how i design a program currently: GameManager + StateManager - gamemanager holds things like the window/event, game loop stuffs. statemanager has an enum which lists possible "states" (we'll get to that) and a state var that can be changed/fetched with setState/getState. the game loop renders certain sprites / takes certain events from different modules (such as things like Player, MapManager, etc.) based on what state the game is in. ie: [code]if(statePtr->getState() == States::PLAYING) { mapPtr->drawMap(); }[/code] moving on, different modules exist "under" the GameManager and StateManager. modules like the Player which has player textures, variables like "isDead" or whatever. depending on that module's needs, it is passed a pointer to the window variable or event variable. from there it has its own draw functions / event actions that'll then be called in the main loop. these module's objects are created in the GameManager's structure and pointers are passed to other modules that need to access each other. so if the map needed a pointer to the player, the player would be created before the map and a pointer to the player would be passed into the map's constructor. i hope this all made sense. so, does this design work well? any suggestions on different kinds of designs? :D
[QUOTE=gparent;39471846]It is redundant, but you're wrong. structs work very similarly to classes in C++, and visibility modifiers aren't special in that regard. They work as expected. Only the default visibility changes. [url]http://codepad.org/WpsVGD8j[/url][/QUOTE] Oh wow, I should have looked more carefully before talking like I knew shit. Thanks for pointing it out! :v:
Do any of you know if it's possible to make your android phone function as an NFC reader that your computer can use? So that I can use my phone to obtain NFC/RFID data and transmit that to my phone.
[CODE] public void PaintCellRectangle(int xStart, int yStart, int xEnd, int yEnd, Cell cell) { for (int y = yStart; y <= yEnd; y++) for (int x = xStart; x <= xEnd; x++) { Cells[x, y] = cell; } } [/CODE] I started adding collision on a level generator that I shamelessly copied off the internet, but I ran into a problem. The problem is that you call the above function like so : [CODE]PaintCellRectangle(0,0,MapWidth,MapHeight, new Cell_*CellTypeGoesHere*);[/CODE] Since you only make one new Cell object they all have the same ID, Bounding rectangle and etc. Can I restructure this in anyway? I've tried a few things with Types but I run into conversion issues.
[QUOTE=Mega1mpact;39504063]Do any of you know if it's possible to make your android phone function as an NFC reader that your computer can use? So that I can use my phone to obtain NFC/RFID data and transmit that to my phone.[/QUOTE] How were you thinking? Via USB? Via Bluetooth?
[QUOTE=jbep3;39503622]So I know very little about character encoding (and it's definitely something I need to educate myself about) but what exactly is the reason characters would be output as [img]http://i.imgur.com/LoGUCgJ.png[/img] Is that the result of a string being output with the incorrect encoding?[/QUOTE] I wasn't going to reply to this, but I'd say do these things: From the limited information I can see in that, it looks like a certain pattern that I've seen but never really researched. From my first impression it looks like you're trying to run UTF-8 through the Windows ANSI code page. If you're printing out UTF-8 to the command prompt, you're gonna have a bad time as Microsoft's C standard library checks to see if it's printing to 'cmd.exe', and if it does it just writes your strings directly to cmd.exe's buffer, and the buffer prints them, assuming it's Windows ANSI. Try printing it to a file and seeing if you get the same results. To troubleshoot this better: 1. Check your input. Is it sane? Do you know your input isn't exactly that horrible glob of characters? What encoding is it? 2. Check your output. Does it use the same encoding as the input? Try writing to a file and opening it with a text editor to see which encoding it is. If you want to learn these things, [url=http://facepunch.com/showthread.php?t=1215368]read this thread[/url].
[QUOTE=Gulen;39504258]How were you thinking? Via USB? Via Bluetooth?[/QUOTE] Doesn't really matter.
I'm pretty certain that it's possible, since you probably have access to both those technologies. When you've got the data from the NFC, you just have to pass it on to the computer.
[QUOTE=Jookia;39504451]I wasn't going to reply to this, but I'd say do these things: From the limited information I can see in that, it looks like a certain pattern that I've seen but never really researched. From my first impression it looks like you're trying to run UTF-8 through the Windows ANSI code page. If you're printing out UTF-8 to the command prompt, you're gonna have a bad time as Microsoft's C standard library checks to see if it's printing to 'cmd.exe', and if it does it just writes your strings directly to cmd.exe's buffer, and the buffer prints them, assuming it's Windows ANSI. Try printing it to a file and seeing if you get the same results. To troubleshoot this better: 1. Check your input. Is it sane? Do you know your input isn't exactly that horrible glob of characters? What encoding is it? 2. Check your output. Does it use the same encoding as the input? Try writing to a file and opening it with a text editor to see which encoding it is. If you want to learn these things, [url=http://facepunch.com/showthread.php?t=1215368]read this thread[/url].[/QUOTE] thanks, tracked it down to a pretty stupid mistake on my part unrelated to the encoding. was accidentally printing a totally different part of the memory compared to what I actually wanted.
[cpp]error: no matching function for call to ‘RenderText::Blended(std::string&, std::string&, SDL_Color*&, int&, SDL_Renderer*&)’[/cpp] I don't even use any kind of references or pointers, I just pass the information straight on. Why is it saying this?
[QUOTE=Asgard;39504812][cpp]error: no matching function for call to ‘RenderText::Blended(std::string&, std::string&, SDL_Color*&, int&, SDL_Renderer*&)’[/cpp] I don't even use any kind of references or pointers, I just pass the information straight on. Why is it saying this?[/QUOTE] How do you expect us to answer this when we don't know what it is you are "passing straight on"?
[QUOTE=Dr Magnusson;39505208]How do you expect us to answer this when we don't know what it is you are "passing straight on"?[/QUOTE] You're sort-of right, however it seemed the cause was a different unrelated error, so it has been fixed now.
simple question - are char's already unsigned? is there anything different from explicitly declaring them unsigned?
[QUOTE=Hentie;39507112]simple question - are char's already unsigned? is there anything different from explicitly declaring them unsigned?[/QUOTE] what language
c++
chars are signed
[QUOTE=WeltEnSTurm;39507391]chars are signed[/QUOTE] Generally they're signed but the standard doesn't care. It designates unsigned char, char and signed char three distinct types. The signedness can [url=http://stackoverflow.com/a/2054959/308323]be forced[/url] to be either with many compilers. [editline]7th February 2013[/editline] Basically char is special in that it's implementation-defined whether it's signed or not, but it regardless is a different and incompatible type (presumably not implicitly castable in standards-compliant mode) to signed char and unsigned char.
In C++11 chars are signed. Because UTF-8 and stuff.
[QUOTE=WeltEnSTurm;39507565]In C++11 chars are signed. Because UTF-8 and stuff.[/QUOTE] Shouldn't they be unsigned then, to allow for bytes > 127? I suppose a byte is a byte is a byte but it would make more sense to me at least
[QUOTE=account;39507829]Shouldn't they be unsigned then, to allow for bytes > 127? I suppose a byte is a byte is a byte but it would make more sense to me at least[/QUOTE] UTF-8 followup bytes are negative most of the time
Sorry, you need to Log In to post a reply to this thread.