Randomly pick a variable but not pick it twice?

Get help using Construct 2

Post » Tue Apr 10, 2012 5:09 am

I have a weapon with about 20 different possible variables for stats affixes such as speed, attack, defense, etc.

I want to randomly choose 3 of those variables and upgrade it by +1.

Problem is, that it may randomly choose that variable three times and I'll only end up with +1 upgrade instead of 3 separate ones.

Is there a way to choose a variable but exclude it from the picking process once it has been chosen the first time?
B
6
Posts: 14
Reputation: 478

Post » Tue Apr 10, 2012 8:35 am

create new wariable 'random choose'
and try this: every 5 seconds set 'random choose' and type this: int(random(1,3) roll number between 1 -3
other event:
if 'random choose' is 1 add +1 to speed
if 'random choose' is 2 add +1 to attack
if 'random choose' is 2 add +1 to defense
+
set 'random choose' to ZERO

but when number has been
B
94
S
19
G
34
Posts: 1,840
Reputation: 27,988

Post » Tue Apr 10, 2012 3:59 pm

use an array. Im not sure if you can copy an arrays data to another array simply so its a bit longer than doin it in normal programming but basically what you do is this:

Make an array. This holds all your things you want randomized (in your case weapon mods)
When you need to generate new weapon stats make a temp array and copy the original array into it.
Now generate your random stat to add and REMOVE that from the temp array. That ensures itll never be picked more than once.

The goal is to have quick disposable temporary arrays to deal out randomized data that can only be used the number of times it exists within the array (you add the same item twice it can get used twice)

Its a bit more difficult to apply to C2 because like I said I dont think you can copy arrays
B
13
S
5
G
2
Posts: 306
Reputation: 3,262

Post » Tue Apr 10, 2012 5:16 pm

[QUOTE=aridale] use an array. Im not sure if you can copy an arrays data to another array simply so its a bit longer than doin it in normal programming[/quote]

@aridale: Consider ArraySource and ArrayDestination, two different arrays.

Have an event (or subevent):
For each element of ArraySource
--> ArrayDestination.at(ArraySource.curX, ArraySource.CurY, ArraySource.CurZ) set to ArraySource.curValue

A simple event that will loop through all the elements and copy them in the destination array.
Of course, you use only the coordinates you need (1D or 2D arrays for example)Kyatric2012-04-10 17:17:59
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Tue Apr 10, 2012 5:38 pm

yeah that would work fine.

On startup fill your main array with all the info you need then whenever you need to randomize your values clear your temp array and then copy over all the data from the main array then randomize your selections.

Just dont forget to remove the data from the temp array once its used and youll never get the same value twice (unless its in the array more than once)
B
13
S
5
G
2
Posts: 306
Reputation: 3,262

Post » Wed Apr 11, 2012 12:51 pm

If I understand you correctly you want to randomly choose 3 of 20 and then upgrade that tree different variables by 1. If that is case look this(I use 10 variables):
http://db.tt/NuRhY5ZA
Or you then want to randomly choose 1 of that randomly picked 3 and upgrade one of that tree? You can figure that out by first situation.

edit: mouse click to trigger addingpodpathos2012-04-11 12:57:49
B
12
S
2
G
2
Posts: 96
Reputation: 1,583


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 22 guests