- Code: Select all
//Global code
int romesoldiers=100;
int romegold=1000;
Then I created a text actor with a draw event and script action. The script line is this:
- Code: Select all
sprintf(text, "Sparta Kingdom\n--------\nSoldiers:%i\nGold:%i", romesoldiers, romegold);
And it worked like a charm. The text actor is able to get the values from the variables and display it.
Since this would give me so much headaches in the future, I started using struct.
changed to this
- Code: Select all
//global code
typedef struct
{
int soldiers;
int gold;
} KINGDOM;
KINGDOM rome;
rome.soldiers=100;
rome.gold=1000;
And change the sprintf line in the actor to this:
- Code: Select all
sprintf(text, "Sparta Kingdom\n--------\nSoldiers:%i\nGold:%i", rome.soldiers, rome.gold);
No errors but all values show zero when I run the game. Is there an error in the code?
Then I do some research and see there's an image in the website showing the global code with struct code inside it. (Sorry had to type it instead of pasting the link because "The maximum number of URLs allowed is 2."
And this text: http://game-editor.com/docs/scripting.htm
Use the Global Code Editor to freely add any 'C' code (arrays, structs, and functions). The sky is the limit when you use this Editor but you should have your feet well grounded in the C Programming Language in order to use the Global Editor effectively. Your knowledge of the 'C' language will serve you well here.
Global Code can be accessed by any script.
Which made me very happy, still can't get the simple text actor to access the struct.
I also found this http://game-editor.com/Using_Global_Code
You cannot use global code to declare complex global objects; If you try to use Struct or Actor* you will encounter problems. Game Editor handles all the interaction, listing, and running of complex Objects. It is not designed for you to add your own in this manner. Use the 'Add Actor' button instead.
You may use Actor* as a local variable for use in a script, if you like.
Ok now I'm confused. Can I use struct in global code for global acessed data or not? Is my code wrong? Am I addressing this issue wrongly?