I wrote a function that uses a global variable, but this variable isn't working properly.
A function that reads / records the number to this variable, not always doing it properly, why?
test.h
int global_var[3]; // Global Variable
class test
{
public:
void write(int nmb);
int read();
};
extern test testt;
test.cpp
#include "test.h"
...
void test::write(int nmb)
{
global_var[0] = nmb;
}
int test::read()
{
return global_var[0];
}
questlua_pc.cpp
...
#include "test.h"
...
test testt;
int pc_test_func_write(lua_State* L)
{
testt.write(lua_tonumber(L,1));
return 1;
}
int pc_test_func_read(lua_State* L)
{
lua_pushnumber(L, testt.read());
return 1;
}
...
{"test_func_write", pc_test_func_write },
{"test_func_read", pc_test_func_read },
This is a sample code.
How can I fix it?