I want to generate a number range (1,10).
So my code is: "Do=Random in Range(1,10) to global variable(generator)
If the number is 5 I want to create a “child 5” for variable “number”
So, I can create it by doing my code: “Do=1 to global variable number.5”
But what if I don’t know the generated number?
I cannot use: “Do=1 to to global variable number.global variabe generator”
What’s the correct sintax?
Before someone asking me to read wiki, I already did it , but didn’t help me.
Variable is one of the most complex part of the engine, It should be more explanatory, showing more examples (imo)
I think the syntax you looking for is:
Do = 1 to global variable number[ToString(GlobalVariable(generator))]
So if for example the value of generator is 6, you set the value of number.6 to 1
I’m going to try that!
Thanks so much! That’s it. You saved my day"
It should have examples like that on wiki.
What if I want now create an object from a goup based on that number generated?
For example let’s take the “6”
I have a group named “Photos” and 10 photos inside.
I created a Variable and children from 1 to 10
Each number has a value (name of photo)
How should be the code?
Among objects Photos create object named …? I don’t know how to complete this.
The most simple way to go about this is to call each photo the same and add a number at the end
And then you can create an object from it name like so:
Among objects GroupName, create object named “Photo”+ToString(GlobalVariable(generated))
ok. Let’s try it! fingers crossed!
Sadly It doesn’t work!
You can download an example from here, at the bottom called “GDevelop5_create_random_object.zip”:
I’ll check it tomorrow!
You won’t believe it! My problem was the “z order”. My objects were being created behind another.
I don’t know how I didn’t check this. I always put an action fot that.
Thanks so much again!