Working with the AGK game engine but I don't think the issue is related to it. it's more about the core code
I have an class of a button. It holds a sprite of a button and a text box which will act as a title of that button
subject_button.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#pragma once
#include "template.h"
class subject_button
{
private:
public:
// variables
float x = 10.0f;
float y = 10.0f;
float temp_y_blaaazzzz = 100.0f;
uString temp_some_stuff = "blaaa blaa blaa";
int sprite_id;
int textbox;
uString textbox_content = "";
subject_button(int CloneSpriteSource);
~subject_button();
void update();
};
|
subject_button.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include "subject_button.h"
subject_button::subject_button(int CloneSpriteSource)
{
//textbox_content = folder_name;
sprite_id = agk::LoadSprite("/media/sprites/spr_button.png");
textbox = agk::CreateText("test");
agk::SetSpriteScale(sprite_id, 1.0f, 1.0f);
agk::SetSpriteVisible(sprite_id, 1);
agk::SetSpriteScale(sprite_id, 2, 1);
agk::SetSpriteColorAlpha(sprite_id, 90);
agk::SetTextSize(textbox, 25);
agk::SetTextMaxWidth(textbox, 360);
agk::SetTextString(textbox, textbox_content);
agk::SetSpritePosition(sprite_id, x, y);
agk::SetTextPosition(textbox, x, y);
agk::Print("ConstructorFired");
}
void subject_button::update() {
//+= 0.05f;
agk::SetTextString(textbox, textbox_content);
agk::SetTextPosition(textbox, x + 100.0f, y + 100.0f);
agk::SetSpritePosition(sprite_id, x, y);
agk::PrintC("button text content: ");
agk::Print(textbox_content);
agk::PrintC("y: ");
agk::Print(y);
agk::Print("");
}
subject_button::~subject_button()
{
}
|
So first things to pay attention to.
In the cpp file, function update(); I'm printing the contents of the varuiable
y using
Take a look at the results. I'm creating a few objects and every object has it's own update() function being run every cycle. So if I have 4 objects created, the Print would be executed 4 times. So you can tell that the objects exist and their function is indeed getting triggered. However the results of printing
Y is some huge negative value, which makes me thing that it doesn't see the variable:
https://imgur.com/a/IVrB9
As you can see, it's defined. I'm not doing anything else with that variable other than reading it and it returns that huge value. This happens with ANY variable I create in the header file.
Next thing to turn your attention to:
The functions of the engine
1 2
|
sprite_id = agk::LoadSprite("/media/sprites/spr_button.png");
textbox = agk::CreateText("test");
|
create the text box and a sprite and both return an ID of the created items to be stored and used to work with those particular items later on. When I'm actually trying to do some stuff with them in the update(); function, Visual Studio prints this in the Output
> Text 3435973836 does not exist
> Sprite 3435973836 does not exist
|
So the two factors, including the fact that I can create any new variable and printing it will result in printing nothing, makes me believe that the cpp file does not see any of the variables I created in the header file.