# Spawn Random Objects :)

0 favourites
• 30 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
• Weeell yeah you can

1/ set some specific patterns in a string like

``````Global test patList = ""
Global number index=0
Global number line=0
+System: start of layout
Local variable curLine=""
-> System: set patList to "01321320
03213210
02313210
23132120
02030102"
-> System: set curLine to tokenat(patList,line,newline)
+System: for "" from 0 to tokencount(curLine,"")-1
-> System: create arrow at x0+loopindex*cs,y0
-> arrow: set a to tokenat(curLine,loopindex,"")``````

etc. And you increment the 'Line' global variable when a line is finished and you redo the creation loop as I did in the capx.

2/ You can use seeded random basically you have to set a seed number (it can be any number) and you have to keep a random value you will use to pseudorandomize stuff.

It looks like that :

``````Global number seed=123456
Global number srand=0
Global number a = 22695477  // just a constant
Global number c = 1  // just a constant
Global number m = 4294967296  // just a constant
+System: On start of layout
-> Set srand to seed
// Each time you want to do a random(3) you do things like that:
+System: for "" from 0 to aCount
-> System: create arrow at x0+loopindex*cs,y0
-> System: Set srand to (srand*a+c)%m
-> arrow: set a to floor((srand/m)*3)``````

That's seeded random in a nutshell

For more indepth read that http://en.wikipedia.org/wiki/Linear_congruential_generator (I used the Borland C/C++ constants)

3/ r0j0 recently post a capx on weighted random... You could use that too.

4/ If you think about convoluted system like recognizing patterns which leads to error and increase the chance to draw these pattern, it will drive you insane.

• Yann,

"-> System: create arrow at x0+loopindex*cs,y0"

- cs is not a system value it says <img src="smileys/smiley6.gif" border="0" align="middle" />

-> arrow: set a to tokenat(curLine,loopindex,"")

-> Cannot set a string to a numbered variable.

• yeah int(tokenat()) I sometimes forget too

Ah yeah 'cs' is an old habit of mine it means "cell Size" I always use that in grid based stuff. If I remember I used arrow.width instead.

• Yann, I tried to get this working but no luck! :(

Take a look : http://dl.dropbox.com/u/51270524/Test.capx

• What I wrote was just a kind of add-on, you still had to keep most of what was in the base capx. But you blindly remove too much stuff. Like setting the order instance variable, the start of layout destruction and x0,y0 setting and of course it was only the loop at start of layout, you have to copy the same one when you end a line (you can also use function to avoid copying this loop code)

Anyway

smitchArrow.capx

• Yann, I see now. But I found a bug, If you set the patlist to: "12341234"

when you press 4 - which should be the right arrow it doesn't recognize it as the correct arrow.

• Oops never mind this was me being dumb :P

• Wait! Yann, it does seem to be a bug. Is this just me or are you experiencing this aswell?

• be carefull:

0 = right

1 = down

2 = left

3 = up

The angle of the arrow sprite = a*90 that's why

if you use 4 the arrow sprite will be properly displayed (4*90 = 360), but the 'a' instance variable is also used to compare the input.

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• haha, I changed these to 2,3,0,1 for the hardmode, so you have to press the opposite key! tricky~ :)

• haha some people got stoned to death with that kind of idea :D

How hard would it be to make it more like a conventional music based game, where the notes come in on a timer and you have to hit the note at the target position to get it correct?

I tried:

System.Compare(Cur = aCount)

Every(1.0 seconds)

-> etc

-> etc

But I guess im completely off as usual?

I get the moving of thing, using lerp right? then if its over the target sprite and the correct key is pressed add 1 to good. I think im right there :)

• very hard

• Yann, ahh dammit! <img src="smileys/smiley6.gif" border="0" align="middle" />

I just want to have the pattered list, but tween the closest one to a target position, then if it's at that position and the correct key is pressed the badaboom! can you help me out? pwetty please *flutters eyelids*

• Can no one help me? [:'(]

• 30 posts