Spawn Random Objects :)

Get help using Construct 2

Post » Sun Feb 05, 2012 10:50 pm

Oh my god thank you very very very very very very very very much. You don't know how happy I am right now! :)
All this useful information! (Like the mute on/off, the easier way to highlight menu-items, the random spawner = introducing me to variables and expressions)
This is priceless and better than a Tutorial!
Thank you very much, I already took a few of your snippets into this game. (Also, to teach myself, I am trying to do stuff a bit different, experiment with these variables~)
We have a really nice community here!

Yours
Black2key
B
18
S
4
G
5
Posts: 27
Reputation: 4,132

Post » Sun Feb 05, 2012 11:46 pm

As a rule of thumb, if you end up with repetition of code, you're doing things wrong.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Feb 06, 2012 1:01 am

@Yann you should write the bible!

What if you wanted to store the order into an array? So things are not so random..
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Mon Feb 06, 2012 2:08 am

@smitchell
not so random... what do you mean?
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Feb 06, 2012 7:34 am

@Yann, I mean us there a way to set the pattern instead if it randomly choosing a arrow
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Mon Feb 06, 2012 11:37 am

Weeell yeah you can
1/ set some specific patterns in a string like
[code]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,"")[/code]
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 :
[code]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)[/code]
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.Yann2012-02-06 11:40:08
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Feb 06, 2012 2:33 pm

@Yann,
"-> System: create arrow at x0+loopindex*cs,y0"
     - cs is not a system value it says

-> arrow: set a to tokenat(curLine,loopindex,"")
     -> Cannot set a string to a numbered variable.
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Mon Feb 06, 2012 3:11 pm

@smitchell
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.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Feb 06, 2012 3:35 pm

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

Take a look : http://dl.dropbox.com/u/51270524/Test.capx
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Mon Feb 06, 2012 6:43 pm

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
Last edited by Yann on Sun Sep 14, 2014 9:41 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: Artpunk, DemantDigitalArt, Magistross, Yahoo [Bot] and 29 guests