0 votes

Having had problems with getting the state of a boolean in another class (I'm using it to see if a body is set as "hiding" when it is returned from a RayCast2D, but other use cases will come up!), I've made the simplest possible code to act as a test-bed.

  1. "Level2" has a "Man" as a child node.
  2. "Man" calls it's getter method in its physicsprocess - this always reports the boolean correctly
  3. "Level2" calls Man's getter method from with Level2's physicsprocess (I have also tried _process as seen below), no matter the value of the bool in Man, it returns "false"

note: I have no code within the program that would alter the bool value i.e. there is no "setter" or any other assignment operator.

Code snippets below - isReportedCorrectly is set to true: (I will provide entire code on request, but the rest is just the standard boilerplate that appears in all classes/scripts)

Getter

bool Man::get_isReportedCorrectly() {
    if (isReportedCorrectly) {
        Godot::print("is true");
    }
    if (!isReportedCorrectly) {
        Godot::print("is false");
    }
    return isReportedCorrectly;
}

Man physicsprocess

void Man::_physics_process(float delta) {
    get_isReportedCorrectly();
}

Level2 _process

void Level2::_process(float delta) {
    currentMan->get_isReportedCorrectly();
}

Results

is false
is true
is false
is true

Expected Results

is true
is true
is true
is true

in Engine by (46 points)

How is isReportedCorrectly defined in Man?
The _process function in Level2 will run before Man's process functions, i'm thinking something is happening before Man's process is called

Header file Man.hpp - declaration

#pragma once
#include <Godot.hpp>
#include <KinematicBody2D.hpp>

namespace godot {
   class Man : public KinematicBody2D {
      GODOT_CLASS(Man, KinematicBody2D);
      private:
      bool isReportedCorrectly;

and in implementation it's only mentioned in _ready as below

void Man::_ready() {
   isReportedCorrectly = true;

Have you managed to get a simple bool to report correctly by the class calling the method itself, and also by calling it as a referenced class method from another class?

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.