Hi,<br><br>I'd like to know if it's possible to create a c++ module with
static functions that I can call from any scene in my game. I could
achieve the same functionality creating an instance in an autoloaded
global script, but then I have to write
get_node("/root/globals/").get_my_instance.function() everywhere. Of
course I'd only save a few characters but I'm more interested if this is
possible, and if not why.<br><br>My minimal non-working example is below:<br>
/* mystaticmodule.h */<br>#ifndef MYSTATICMODUDE_H<br>#define MYSTATICMODULE_H<br><br>#include "object.h"<br><br>class mystaticmodule : public Object<br>{<br> OBJ_TYPE(mystaticmodule, Object);<br><br>protected:<br> static void _bind_methods();<br> <br>public:<br><br> static int get_int();<br>};<br><br>#endif<br><br>/* mystaticmodule.cpp */<br>#include "mystaticmodule.h"<br><br>void _bind_methods()<br>{<br> ObjectTypeDB::bind_method("get_int",&mystaticmodule::get_int);<br>}<br><br>int mystaticmodule::get_int()<br>{<br> return 42;<br>}
<p class="CodeBlock">compiling (on ubuntu: scons platform=x11) yields following errors:<br></p>
g++ -o modules/mystaticmodule/mystaticmodule.x11.tools.64.o -c -g2 -Wall -DDEBUG_ENABLED -DDEBUG_MEMORY_ENABLED -DFREETYPE_ENABLED -DOC_X86_ASM -DDEBUG_MEMORY_ALLOC -DSCI_NAMESPACE -DENABLE_DEPRECATED -DOPENGL_ENABLED -DALSA_ENABLED -DJOYDEV_ENABLED -DX11_ENABLED -DUNIX_ENABLED -DGLES2_ENABLED -DGLES_OVER_GL -DMUSEPACK_ENABLED -DSQUISH_ENABLED -DVORBIS_ENABLED -DOPUS_ENABLED -DTHEORA_ENABLED -DTHEORALIB_ENABLED -DPNG_ENABLED -DDDS_ENABLED -DPVR_ENABLED -DJPG_ENABLED -DWEBP_ENABLED -DSPEEX_ENABLED -DTOOLS_ENABLED -DGDSCRIPT_ENABLED -DMINIZIP_ENABLED -DXML_ENABLED -DETC1_ENABLED -DGLEW_ENABLED -DGLEW_STATIC -Icore -Icore/math -Itools -Idrivers -I. -Iplatform/x11 -I/usr/include/freetype2 -Imodules/mystaticmodule modules/mystaticmodule/mystaticmodule.cpp<br>In file included from core/object.h:696:0,<br> from modules/mystaticmodule/mystaticmodule.h:4,<br> from modules/mystaticmodule/mystaticmodule.cpp:1:<br>core/object_type_db.h: In instantiation of 'static MethodBind* ObjectTypeDB::bind_method(N, M) [with N = const char*; M = int (*)()]':<br>modules/mystaticmodule/mystaticmodule.cpp:5:63: required from here<br>core/object_type_db.h:337:49: error: no matching function for call to 'create_method_bind(int (*&)())'<br> MethodBind *bind = create_method_bind(p_method);<br> ^<br>core/object_type_db.h:337:49: note: candidates are:<br>In file included from core/method_bind.h:346:0,<br> from core/object_type_db.h:33,<br> from core/object.h:696,<br> from modules/mystaticmodule/mystaticmodule.h:4,<br> from modules/mystaticmodule/mystaticmodule.cpp:1:<br>core/method_bind.inc:68:13: note: template<class T> MethodBind* create_method_bind(void (T::*)())<br> MethodBind* create_method_bind( void (T::*p_method)() ) ...<br>
<br><br><br>