Cheerp is a tool that transpiles C++ code to js/wasm. Screeps is an interactive programming game.
How can I access the Game.time
variable in my C++ code after it has been transpiled for Screeps?
#include <cheerp/client.h>
#include <iostream>
using namespace std;
namespace client {
class Game : public Object {
public:
static volatile double time;
};
extern volatile Game &Game;
}
void webMain() {
cout << __TIME__ << ": The current time is: " << client::Game.time << endl;
}
I have experimented with:
extern
,volatile
, andstatic
keywords- references and pointers
- both
client
andcheerp
namespaces - Inheriting from
Node
/Object
- Different data types such as
int32_t
,double
, andfloat
However, I keep encountering issues like:
NaN
0
1
- fatal errors related to data types in the compiled code
What is the correct approach to interact with JavaScript objects and variables from C++ code? The documentation provided by cheerp is very limited...
Note: It seems that cheerp is not generating the correct JavaScript output. There are inconsistencies in how the Game
object is handled, leading to attempts to index Game.d
as an array rather than Game.time
.