How to set global variable to command??

Get help using Construct 2

Post » Mon Mar 07, 2016 4:57 am

Hello I want to set global variable to command to set on the other layout
I have variable name "GLOBAL_MONSG" set to ""choose(1,2,3,4,5,6,7)"" I just want to random monster to spawn in layout battle
in layout battle I have variable name "RandomMonster" and set to "GLOBAL_MONSG" because I set it to command to random but it doesn't work. How can I set monster to random in previous layout before I go in battle? Please Help me :( ! Thank you.
B
4
Posts: 8
Reputation: 216

Post » Mon Mar 07, 2016 5:20 am

When you put "choose(1,2,3,4,5,6,7)" inside quotation marks as you have, it is no longer an expression, but a string.

I don't think you can have an expression inside a variable. Are you trying to have the random number picked when you go into the next layout? Or have the next layout pick the random number?

You can:

1. Use an action to set your GLOBAL_MONSG variable to choose(1,2,3,4,5,6,7), in which case a random number whole number between and including 1 and 7 will be stored in the variable. Then you can set RandomMonster to GLOBAL_MONSG and get the same number.

2. Use a function that returns "choose(1,2,3,4,5,6,7)", and have your action set your RandomMonster variable to your function output.
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Post » Mon Mar 07, 2016 5:47 am

oosyrag wrote:When you put "choose(1,2,3,4,5,6,7)" inside quotation marks as you have, it is no longer an expression, but a string.

I don't think you can have an expression inside a variable. Are you trying to have the random number picked when you go into the next layout? Or have the next layout pick the random number?

You can:

1. Use an action to set your GLOBAL_MONSG variable to choose(1,2,3,4,5,6,7), in which case a random number whole number between and including 1 and 7 will be stored in the variable. Then you can set RandomMonster to GLOBAL_MONSG and get the same number.

2. Use a function that returns "choose(1,2,3,4,5,6,7)", and have your action set your RandomMonster variable to your function output.


I tried to set GLOBAL_MONSG variable to choose(1,2,3,4,5,6,7) but it only random for me for one time in battle, I want to random new monster every battle too.
I don't understand the second method :|
B
4
Posts: 8
Reputation: 216

Post » Mon Mar 07, 2016 7:29 am

If you want new random every battle, why not just set RandomMonster to choose(...)?

I guess you want to set a list of which monsters you can choose from before going into the battle. In that case I would create an array - Start with a width of 0, and then push to fill it with the possible choices, then in the battle layout set RandomMonster to Array.At(floor(random(Array.Width)).

That's the first thing I could think of, there might be an easier way, maybe someone else could chime in.
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Post » Mon Mar 07, 2016 8:42 am

oosyrag wrote:If you want new random every battle, why not just set RandomMonster to choose(...)?

I guess you want to set a list of which monsters you can choose from before going into the battle. In that case I would create an array - Start with a width of 0, and then push to fill it with the possible choices, then in the battle layout set RandomMonster to Array.At(floor(random(Array.Width)).

That's the first thing I could think of, there might be an easier way, maybe someone else could chime in.


Yes I want to set before go to battle layout
I dont set RandomMonster To choose(..) because it have many battle with different random monster

Okay. I understand but i want to set random "Orb" too, I use number to set random orb and it isnt start with 0 and like 0,1,2,3,4,...
I dont know what to do now maybe I will set all in battle layout.
B
4
Posts: 8
Reputation: 216

Post » Mon Mar 07, 2016 11:14 am

In my example I run the for each
and my enemys are in this case just another frame from the animation (but can be whatever you want)

system for each objEnemy | set animation frame to > choose (0,1,2,3)

https://www.dropbox.com/s/y4ixsuyuzo0pj ... .capx?dl=0

  • System > On start of layout | system > load game from slot "brain"
  • System > On load failed | system > scroll to obj_Forum
B
17
S
8
G
5
Posts: 340
Reputation: 4,707


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 18 guests