Choosing a random layout.

Get help using Construct 2

Post » Fri Nov 15, 2013 2:21 am

I am making a game where layouts are chosen randomly from a pool of 250 layouts. When the game randomly chooses a layout, the game should not send the player to any menu layouts, or repeat previously chosen layouts. What's the easiest way to do what I want to do? I really don't want to create >250 events based off a randomly chosen variable.
B
9
S
3
Posts: 52
Reputation: 1,260

Post » Fri Nov 15, 2013 2:32 am

nextroom as global variable
name your layouts 1,2,3, etc

Make a function: chooselayout

on function
set nextroom to
random(int(1,250))

Go to layout nextroom

B
71
S
24
G
11
Posts: 452
Reputation: 12,343

Post » Fri Nov 15, 2013 2:43 am

@Draspur
Very helpful, but I ran into an error: http://i.imgur.com/xKxm3h0.png
B
9
S
3
Posts: 52
Reputation: 1,260

Post » Fri Nov 15, 2013 2:48 am

[QUOTE=HacksawUnit] @Draspur
Very helpful, but I ran into an error: http://i.imgur.com/xKxm3h0.png[/QUOTE]

You must have your global value set as text, set it as a number. You'll also have to set your variable as a string in the go to layout by name event. Use this:

str(nextlevel)
B
71
S
24
G
11
Posts: 452
Reputation: 12,343

Post » Fri Nov 15, 2013 2:53 am

@Draspur I used int(random(1,250)) and it accepted. I will report back with results.
B
9
S
3
Posts: 52
Reputation: 1,260

Post » Fri Nov 15, 2013 2:55 am

[QUOTE=HacksawUnit] @Draspur I used int(random(1,250)) and it accepted. I will report back with results.
[/QUOTE]

Sounds good, just curious, why do you have 250 layouts?
B
71
S
24
G
11
Posts: 452
Reputation: 12,343

Post » Fri Nov 15, 2013 3:02 am

@Draspur The player must get through 100 different rooms per game, and having a pool of 250 allows for many unique playthroughs.
B
9
S
3
Posts: 52
Reputation: 1,260

Post » Fri Nov 15, 2013 4:57 am

[QUOTE=HacksawUnit] @Draspur The player must get through 100 different rooms per game, and having a pool of 250 allows for many unique playthroughs.[/QUOTE]

Like a dungeon crawler?
B
71
S
24
G
11
Posts: 452
Reputation: 12,343

Post » Fri Nov 15, 2013 8:48 am

it is easier to use round than int. so basicly round(random(1,250)) . To save an event just use
onEvent -> go to layout "room"&round(random(1,250)).
Keep a global variable for the amount of rooms done.
B
9
S
3
G
3
Posts: 70
Reputation: 1,990

Post » Fri Nov 15, 2013 10:54 am

Hi,

I think you might want to use some shuffling or helper storage, to avoid getting into the same room twice. Two ways (there are certainly more):

1) create array of size 250
2) fill it with consecutive integers
3) shuffle random pairs of a hundred or more times
4) make the player go from room to room, according to the (shuffled) order of elements in your array.

Way #2:

1- draw random integer as in examples you've seen above
2- if integer is already in the helper container (#3 below), repeat drawing
3- store the number in a helper array/string etc
4- proceed to the selected layout

Hope it helps,
Greg

B
18
S
3
G
3
Posts: 83
Reputation: 3,736

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 25 guests