[code] Quick coding problems, small bugs, syntax errors, etc

I realised we don't have a thread like this so I am starting one.

Post here any tiny problems that you're still working out that you don't feel warrant a whole thread. Got a syntax error somewhere and can't locate it? Etc.
Does FileTest.exist?() always return false when the file specified is located in the Game.rgssad?
So uh...

Imagine I have, in C++,


class Game
{
public:
Player *player;
};


*player is a pointer to a Player.


I want to reference Player in a function,


void Game::keyHandler(int key)
{
player->Sprite->Rotate(4); // expression must have a pointer to class type
*player->Sprite->Rotate(4); // expression must have a pointer to class type
player.Sprite->Rotate(4); // expression must have a class type
Game::player->Sprite->Rotate(4); // expression must have a pointer to class type
}



What should I be doing?
You should be using just player->function() or player->member

My guess is that Sprite is not a pointer and that is why it's complaining on that line. If you post your Player class I should be able to show you where.
In player I have:

class Player : Character
{
public:
sf::Sprite *Sprite;
};


sf::Sprite has a function Rotate(int angle);.
Hmm, that's odd. At first glance, it looks like the first thing you did should work. I will try some stuff, but codepad.org is down right now. For reference, something like codepad.org is a good place to go so that you can isolate some simple code to represent one thing that you suspect may be causing an issue.

As a side note, I recommend you do not name something the same as the class. Naming it sprite or m_sprite or something like that is better. The namespace means that you can do it, however, namespaces aren't meant for you to intentionally name things the same. Instead, it is so that when you are using multiple libraries, they may have the same name since a lot of different libraries will use the same name for different things. (for example std::vector is a dynamic array, but in other libraries, a vector may represent a math vector)
Ok, so with the information you've given us, I did this on codepad:

http://codepad.org/uSIt6Bga

So that code works as expected, so that tells me that the code you posted here isn't quite equivalent to what you actually have. Perhaps if you post the full classes, we can find what's going on.
udivision wrote:
Does FileTest.exist?() always return false when the file specified is located in the Game.rgssad?

FileTest.exist? checks for existence in the normal file system. If the file you check for also happens to be present in the file system it will return true.
For resources located in the .rgssad you can try to load them using Bitmap.new or load_data and catch the exceptions raised when they are not present. Not pretty, but it seems the best you can do short of decrypting the .rgssad.

*hugs*
Anyone know where I've gone wrong here? "Not a valid mysql resource" on the second line.

$result = mysql_query("SELECT * FROM `error_logs`");
while ($row = mysql_fetch_array($result))
{
}
Well first it could be that you didn't enter table name correctly, check if it really is error_logs and not error_log or err_log or something.

Second thing which might be a problem are the `` between table name but usually that shouldn't be the case. Try removing those, so in the end you'll have:

  1.  
  2. $result = mysql_query("SELECT * FROM error_logs");
  3. while ($row = mysql_fetch_array($result))
  4. {
  5. }
  6.  
Expand to see the code.


I always simply use SELECT * FROM table_name without ``, the only time I use them is when creating the table, and it works for me. :)

EDIT:
Also the second row has a bit of problem, you see that it will always call mysql_fetch_array (even when there is actually no table data to read?)

I would do it this way.

  1.  
  2. $result = mysql_query("SELECT * FROM error_logs");
  3.  for ($i = 0; $i < mysql_num_rows($result); $i++) {
  4.   $row = mysql_fetch_array($result);
  5.   // code here
  6.  }
  7.  
Expand to see the code.
Only thing that looks odd is the single quotes on error_logs
Content Hidden Spoiler
Ugh.

Trying to use gdiplus, can't find any examples, this doesn't work:


______________________
#include <GdiPlus.h>
#include <GdiPlusBitmap.h>

Gdiplus::Bitmap* pBmp = Gdiplus::Bitmap::FromFile(L"bitmaptex.bmp", false);



Error: Gdiplus has no member "Bitmap"

I am in Visual Studio 2010, C++.

I have tried

____________
using namespace System.Drawing;


And get a squiggly line under System. saying it must be a namespace name.


Sorry, irrelevant now, I have found a better library to use.
Wyatt wrote:
So uh...

What should I be doing?


is Sprite a sf::Sprite?
Also what version are you using? because in 2.0 rotate() is with lower case letter.
http://www.sfml-dev.org/documentation/2.0/classsf_1_1Sprite.php

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=73512