Randomly selecting a global variable

For questions about using Classic.

Post » Wed Apr 07, 2010 9:20 am

Upon collision with an object I would like 1 added to a random global variable. I would like to choose which global variables 1 can be added to from the random selection as well. I have no idea how to start this.

Thank you for the help.
B
8
S
1
G
2
Posts: 79
Reputation: 1,108

Post » Wed Apr 07, 2010 2:22 pm

You need to use a naming convention to organize your global variables so you can do something like set global variable Gvariable&str(random(10)+1) to random(1). All your global variables you want to be included should of course have the same beginning then you use a number to tell them apart (eg. v1, v2, v3 etc). Remember to right click on set global variable prompt and choose "use expression" so that you can set the variable to an expression. When you start using naming conventions more, you may want to start looking into the text manipulator so that you can use the useful "replace" action. I'm sorry I can't post an example cap for you.
B
2
S
2
G
4
Posts: 259
Reputation: 1,968

Post » Wed Apr 07, 2010 2:45 pm

What about just setting up an array and then randomly picking form one of the cells?
B
28
S
8
G
8
Posts: 530
Reputation: 7,154

Post » Wed Apr 07, 2010 3:10 pm

[quote="manontherun":1663chjg]You need to use a naming convention to organize your global variables so you can do something like set global variable Gvariable&str(random(10)+1) to random(1). All your global variables you want to be included should of course have the same beginning then you use a number to tell them apart (eg. v1, v2, v3 etc). Remember to right click on set global variable prompt and choose "use expression" so that you can set the variable to an expression. When you start using naming conventions more, you may want to start looking into the text manipulator so that you can use the useful "replace" action. I'm sorry I can't post an example cap for you.[/quote:1663chjg]
I'm not sure that will work. I'd go with either a global array, or store a temporary value generated by random(), then have a series of subevents along the lines of: random value = 0, use global('abc'), random value = 1, use global('def'), etc. (Don't put random() in each line or it will generate a new random number for each line!)
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Wed Apr 07, 2010 6:02 pm

I use naming conventions all the time and works perfectly. It makes eventing easy - just have to get use to strings, tokens and converting values.
B
2
S
2
G
4
Posts: 259
Reputation: 1,968

Post » Wed Apr 07, 2010 9:49 pm

Thank you all for your time. I am afraid this looks to be a bit too complex for me at the moment and I really need to finish up as much of the game as possible by May for a Game Developers Conference (I am really mainly just an art, music, and concept guy). If anyone can post an example cap so I can look at this further I would really appreciate it. Everyone who has helped is going into the credits of the game if they want to.
B
8
S
1
G
2
Posts: 79
Reputation: 1,108

Post » Wed Apr 07, 2010 10:19 pm

[quote="Ashley":1vou1jai][quote="manontherun":1vou1jai]You need to use a naming convention to organize your global variables so you can do something like set global variable Gvariable&str(random(10)+1) to random(1). All your global variables you want to be included should of course have the same beginning then you use a number to tell them apart (eg. v1, v2, v3 etc). Remember to right click on set global variable prompt and choose "use expression" so that you can set the variable to an expression. When you start using naming conventions more, you may want to start looking into the text manipulator so that you can use the useful "replace" action. I'm sorry I can't post an example cap for you.[/quote:1vou1jai]
I'm not sure that will work. I'd go with either a global array, or store a temporary value generated by random(), then have a series of subevents along the lines of: random value = 0, use global('abc'), random value = 1, use global('def'), etc. (Don't put random() in each line or it will generate a new random number for each line!)[/quote:1vou1jai]
This will work the best. Trust me. It's not complex either! :)
B
2
S
2
G
2
Posts: 372
Reputation: 1,794

Post » Thu Apr 08, 2010 12:11 am

[quote="Mr Wolf":ga648z14][quote="Ashley":ga648z14][quote="manontherun":ga648z14]You need to use a naming convention to organize your global variables so you can do something like set global variable Gvariable&str(random(10)+1) to random(1). All your global variables you want to be included should of course have the same beginning then you use a number to tell them apart (eg. v1, v2, v3 etc). Remember to right click on set global variable prompt and choose "use expression" so that you can set the variable to an expression. When you start using naming conventions more, you may want to start looking into the text manipulator so that you can use the useful "replace" action. I'm sorry I can't post an example cap for you.[/quote:ga648z14]
I'm not sure that will work. I'd go with either a global array, or store a temporary value generated by random(), then have a series of subevents along the lines of: random value = 0, use global('abc'), random value = 1, use global('def'), etc. (Don't put random() in each line or it will generate a new random number for each line!)[/quote:ga648z14]
This will work the best. Trust me. It's not complex either! :)[/quote:ga648z14]

That procedure does seem the most simple, the only problem is that I have no idea how to implement a "Random()". How would I create it in an Event? Thank you all again.
B
8
S
1
G
2
Posts: 79
Reputation: 1,108

Post » Thu Apr 08, 2010 12:52 am

While using an expression would be nice if you have a large number of variables to work with, I'm not able to get Construct to allow me to do that...

Anyway, simple conditional statements would be fine in most cases. Here's a quick .cap with an example (made with v0.99.84): Random Global

Also, here is a good page of the wiki to know of, if you don't:

http://sourceforge.net/apps/mediawiki/c ... xpressions

It explains things like the Random() function.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Thu Apr 08, 2010 7:01 pm

[quote="Silent Cacophony":2vum4eem]While using an expression would be nice if you have a large number of variables to work with, I'm not able to get Construct to allow me to do that...[/quote:2vum4eem]Check your PM.
B
2
S
2
G
4
Posts: 259
Reputation: 1,968

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests