[Solved] Global code questions

You must understand the Game Editor concepts, before post here.

[Solved] Global code questions

Postby digiot » Wed Nov 06, 2013 11:37 pm

My recent failure in trying to use the global code made me believe, I must
have misunderstood something very fundamental here.

There are rare examples of more complex global code in the docs/tuts, than
just declaring some global vars and functions.

And even such simple things I can't get to work.
Maybe, I'm missing something, concerning the access to the global.c file.

Where must it reside, in the main game dir, where the .geds are stored ?

Are there more than 1 <whatever>.c files allowed, or does that confuse GE ?

When I'm ready in the global code editor, I choose File -> Save.

Starting now the game mode, it seems, that the global code I've saved in
global.c is not included.
When I open the editor, it is empty all the time.

What is wrong here, how gets GE access to the global.c ?

More generally, what else can I do in the global code, than just declaring
vars and functions ?

Can I put real pieces of code in there, and how can I realize that ?

Does GE run direct code in the global code at all ?

And if so, can I just put the commands in there, or do I have to put them
into a code block, or what ?

Really important for me, to get that cleared. Depending on the result, maybe
I have to rework the (planned) implementation of my game concept...
Last edited by digiot on Thu Nov 14, 2013 10:20 pm, edited 1 time in total.
User avatar
digiot
 
Posts: 211
Joined: Sat Mar 17, 2012 2:29 pm
Score: 7 Give a positive score

Re: Global code questions

Postby DarkParadox » Thu Nov 07, 2013 4:48 am

Yes, you've missed something. To write a global script you open the global code menu by clicking "scripts" in the main menu and then "global code", or by clicking the "global code" button in any scripting window.
When you finish writing code in the Global Code menu, you need to type a name and click "add" in the lower bar.
Image
Any variables or functions you made in Global Code can then be used in any script you make.
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: Global code questions

Postby digiot » Thu Nov 07, 2013 12:02 pm

@ DarkParadox : Nice, that you drop in here !
Have recently noticed your great contributions here, if you had not updated your
stuff, I would've never found it !

Your help is also very appreciated here, but did you really read my post ?

Hope, my Pidgin is halfway understandable, I tried my best...

What my problems are:

- The file, where GE stores the global code. I'm not sure, if it gets registered
correctly inside GE. I did save it in the main game dir, is there anything else
I have to do ?
And what about storing alternative global.c files in that dir, is that allowed ?

- The global code itself. What I want to achieve, is, to have a kind of codeflow,
something like the "void main(){}", inside the global code.
Like in pure C, first the constants, variables and structures, then the subroutines
and functions.
And what then ? Can there exist a codeblock, or what construct ever, where I can
put in global code, to control GE with ?

Hope, someone can make that clear for me !
User avatar
digiot
 
Posts: 211
Joined: Sat Mar 17, 2012 2:29 pm
Score: 7 Give a positive score

Re: Global code questions

Postby skydereign » Fri Nov 08, 2013 11:44 pm

digiot wrote:Your help is also very appreciated here, but did you really read my post ?

Hope, my Pidgin is halfway understandable, I tried my best...

DarkParadox did. The major thing you aren't understanding is that gE doesn't deal with .c files. You can save global code into .c files if you want, but how to add code to your gE game, is to click the [Add] button. So if you copy the following script into global code, you then have to give the script a name, and click [Add], otherwise it won't do anything.
Code: Select all
void
main ()
{
    // do something
}

digiot wrote:- The file, where GE stores the global code. I'm not sure, if it gets registered
correctly inside GE. I did save it in the main game dir, is there anything else
I have to do ?
And what about storing alternative global.c files in that dir, is that allowed ?

To reiterate, you have to click add to add the script to the ged. The .c files are not actually used by the game.
digiot wrote:- The global code itself. What I want to achieve, is, to have a kind of codeflow,
something like the "void main(){}", inside the global code.
Like in pure C, first the constants, variables and structures, then the subroutines
and functions.
And what then ? Can there exist a codeblock, or what construct ever, where I can
put in global code, to control GE with ?

You can't fully achieve typical control you'd expect from C. gE doesn't give you access to the game loop. Any code that is run, must be called from events, and you cannot alter how events take place. However, global code is declared before the main loop, so you can add your functions and variable declarations there.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Global code questions

Postby digiot » Sat Nov 09, 2013 3:16 pm

Sorry, I was a victim of false and missing information !

Somewhere in a forum thread, there was stated, that putting a name into the text field,
and clicking "Add" then, were an alternative method of variable creating, to the native
one, clicking "Variables" and using the "User Variables" dialog.

Just wondered, why the variables are not listed in the var - list...

The global code itself I always saved wrongly with the "File" menu !

@ DarkParadox : Sorry, now I understand, thanks !

@ skydereign : Yes, like above, and you are the thirst one, who made it such clear !

The magic words are :

skydereign wrote:...you have to click add to add the script to the ged. The .c files are not actually used by the game.


So the "File" menu is more or less a kind of an import/export function, and since you
can't copy/paste to/from GE, the only way to do that ?

I've tested with some global codes, and the vars are nicely displayed in the list,
among the vars, created through the "Variables" dialog.

skydereign wrote: You can't fully achieve typical control you'd expect from C.


No, that's not what I mean, in contrast, the less C I need, the better !

What I'm after, is, to have a script run at the beginning of the game or a level, which
will set up several things, like new backgrounds, animations, objectwaves and what not.

But I believe, I've found the solution : Just using a special actor, or one which has
no events in the game, and putting the code into its script action.

skydereign wrote: gE doesn't give you access to the game loop. Any code that is run, must be called from events, and you cannot alter how events take place.


That is another essential statement !


Thanks both, DarkParadox and skydereign, you have provided very useful informations !
User avatar
digiot
 
Posts: 211
Joined: Sat Mar 17, 2012 2:29 pm
Score: 7 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest