Tips for Beginners

Case Sensitivity of Names

In GD the names for Objects, Variables and Functions are case sensitive.
For example: Variable(MyVariable), Variable(Myvariable) and Variable(myvariable) are 3 different ones.
In addition, there are 3 types of variables: global variables, scene variables and object’s variables.
For example, GlobalVariable(color), Variable(color) and Object.Variable(color) are 3 different variables with the same name: global one, scene one and variable of the Object.

Often mistakes:

Function MyFunction
Launch myfunction() - wrong: ‘MyFunction’ will never be launched. The right way: Launch MyFunction()

GlobalVariable(color) = 5
Do +3 to Variable(color) - wrong. ‘3’ will be added to Scene variable ‘color’ if such exists, not to Global one. The right way: Do +3 to GlobalVariable(color)

Using Functions

  • Double click on ‘Extensions’ in ‘Project manager’ window.
  • In ‘Extensions available’ check ‘Function events’. Close ‘Extensions’ window. Close and reopen Scene editor window. Now in Event editor under ‘+Add…’ or ‘+Other’ will be available ‘Function’.

To insert function click on ‘+Add’ or ‘+Other’. In the appeared window type in the name of the function and close this window.
All events and sub-events which are included in the function will be executed only when this function is called.

To call the function use Action: Function>Launch function.
Type in its name and parameters if it has them.
Note: Parameters shall be in text format. If you use numbers you need to convert them to text: ToString(5) will convert number ‘5’ to text ‘5’.

To use parameters in the launched function use expression like this: Function::Parameter(0). It will refer to the first parameter of the function.
Function::Parameter(1) will refer to the second parameter and so on.
Note: Because parameters are in text format you’ll need to convert them to numbers if you want them to be numbers: ToNumber(Function::Parameter(0)) will give you number ‘5’ which you can use in mathematical expressions.

In GD you can have recursive functions - functions which are calling themselves. Big plus to GD!

Example of function by erdo: (The source file is here: viewtopic.php?f=19&t=5425&p=44268#p44268)
function_example.png

Great tips and explanations! :laughing:

Also (for people using GD on Windows) always check up case sensitivity of file names (mostly for music/sound/storage) in your events, or your project won’t compile and/or run under Linux.

For Windows File.xml and file.XML may be same file, but for Linux it is not!

When you create an object by using Object.Width() or Object.Height() to locate it, they will be = 0, because (a bug?) the instance of the object is still not created.
So, first you need an action to create the object in some location on the scene, and then to move it using Object.Width()/Height().
Example:
Action: Create Object at 0+Object.Width(), 0+Object.Height() - wrong (in GD, in Construct 2 it’s OK :wink: ) - will create Object at position 0, 0 without shifting it by its width and height.
The right way is:
Action 1: Create Object at 0, 0.
Action 2: Do +Object.Width(), +Object.Height() to the position of Object

Just a note: I think it’s because in Contstruct 2 you have to (I think it’s required) add at least one instance before start… aaaand the created object doesn’t become the reference one instantly :wink:

I’m checking it now, try this:
Create an object “Object”, and add an instance of “Object” at random place (as in Construct 2), then add this event:


It will consider every “Object”, and as you added one, there will be an instance to check the methods “Width()” and “Height()” :slight_smile:

I’m not sure, but “Consider all instance of” is not needed there because Game Develop has no instances considered so it will automatically considers all of them.

I thought that too, but GD (apparently) take the “Instance to be created” as the reference one… it could be possible if GD knows that one instance will be created and set it as reference at the beginning of the event.

I don’t know, and it’s strange for me… but if you don’t add the “Consider all objects…” action, the Width() and Height() methods return 0 (instance not found or something like that) :confused:

EDIT: Also works if you add the condition “Consider all objects” instead the action.

Wow, lots of great info in there. Thanks for taking your time to do that.