I want to write some script (I’m willing to learn yet another scripting language if that’s what it takes) and store it in a file.
I want to open that file from my cocos2d-x C++ project and execute the script.
I (obviously!) need to be able to communicate between the script and C++ (so pass parameters and return values) but I’d be happy to have that limited (i.e. I don’t need the scripting language to be aware of C++ objects - if it can pass pack a pointer or even an array of variables)
I had thought LUA might be the way to go - but it seems to me that nobody is using it (certainly the messages on this forum are few and far between and with fewer and more distant answers)
Surely some of you out there are using some sort of scripting language from within your Apps?
Any advice gratefully received - before I develop my own scripting language!!
It’s possible to use lua or javascript from cocos2d-x C++ project. right now I’m implementing javascript on my cocos2d-x C++ project, but there are several drawbacks when you implement scripts.
You can’t debug what’s going on inside the script, and it’s hard to see where the error happened. usually I used logging to capture the errors.
Memory management is hard (at least on javascript) since it uses garbage collector which triggered automatically (but you can also force garbage collect from the script or C++ side)
You have to write wrappers/proxies for every single class that you want to expose to the script side (since I haven’t tried the auto binding script provided by cocos2d-x)
Javascript’s OOP is confusing
Well, my prior knowledge about javascript is not much, but there are also advantages using scripting:
You can update anything on the fly using the scripts. In my case, I used them for UI, formula and some unit’s mechanic and I put it on my servers so players just need to download them without installing a new client
You can add methods for your C++ class in the scripts
You can also obfuscate the scripts by compiling them so anyone can’t see what’s inside the file
I really only want to do simple stuff in script to start with.
My initial requirement is to write some calculations in there to create terrain for a side-scrolling game - so even a method GetPoints() that returned an array of Vec2() would be fantastic!
Can you point me at any ‘noob guide’ on getting this set up initially?
what I really would like is the original “HelloWorld” c++ app from cocos2d-x, with the changes made to load a script which (say) returns a string that the C++ app displays.
That would be enough for me to see how it hangs together and then build on, and ask questions when I get stuck!
Not asking you to do that for me - but if you can point me in the right direction that would be fantastic!
Well, I used this as reference but I don’t think it’s gonna be useful. Maybe you can try to learn from js-tests in the tests folder and also from cocos2d-js codes.