Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[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.
 
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.
 
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.
 

Zeriab

Sponsor

udivision":rhxi5nou said:
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:

Code:
 

$result = mysql_query("SELECT * FROM error_logs");

while ($row = mysql_fetch_array($result))

{

}

 

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.

Code:
 

$result = mysql_query("SELECT * FROM error_logs");

 for ($i = 0; $i < mysql_num_rows($result); $i++) {

  $row = mysql_fetch_array($result);

  // code here

 }

 
 
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.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top