Page 1 of 2
random
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
Posted:
Sun Feb 16, 2014 1:30 am
by barney12345
Ok, how could I have randomly placed bad guys that are between x +310 and -310 but anywhere on the y axis but without having more than 3 on screen at the same time?
Re: random
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
Posted:
Sun Feb 16, 2014 6:01 am
by CrackedP0t
1. Make an Integer variable called "badguycount". In the CreateActor event of the bad guy, put this code:
- Code: Select all
badguycount++;
In the DestroyActor event, put this code:
- Code: Select all
badguycount--;
2. Make an actor that will place the bad guys; he should just be off the screen or not visible.
3. In his Draw Actor event, put this script:
- Code: Select all
if (badguycount <= 3) {
CreateActor("badguy", "badguyanimation", rand(310) - 620, rand(view.width) - view.width* 2, true);
}
You could replace view.width with any number; I'm just assuming that the view won't move.
That should do it; if you have questions, make sure to post them!
Re: random
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
Posted:
Sun Feb 16, 2014 7:27 am
by barney12345
thanks for that, just that my view actor does move, so there is an error code. so what would the numbers be then if it was 310 to -310(not exact, but where about)
Re: random
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
Posted:
Sun Feb 16, 2014 8:10 am
by CrackedP0t
What's going wrong, and what's the error?
Re: random
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
Posted:
Sun Feb 16, 2014 8:45 am
by barney12345
Error line 2: Incompatable types, cannot convert from "double" to "* const char"
Re: random
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
Posted:
Sun Feb 16, 2014 4:57 pm
by CrackedP0t
I'm sorry, I forgot 2 arguments in the CreateActor function...
And, actually, the view.width should be replaced with view.height if you're using the Y axis, which you are.
This is better.
- Code: Select all
if (badguycount <= 3) {
CreateActor("badguy", "badguyanimation", "(none)", "(none)", rand(310) - 620, rand(view.height) - view.height* 2, true);
}
The first "(none)" is the parent, and the second "(none)" is the path. I'm just assuming there won't be either.
Re: random
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
Posted:
Sun Feb 16, 2014 8:05 pm
by barney12345
It still doesn't make any of the badguys, or am I meant to add a timer thing which will create a bad guy
Re: random
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
Posted:
Sun Feb 16, 2014 9:49 pm
by CrackedP0t
Hmmm... maybe you could post the GED?
Re: random
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
Posted:
Mon Feb 17, 2014 7:14 am
by barney12345
here you go, ignore the graphics and the weird control thing
Re: random
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
Posted:
Mon Feb 17, 2014 5:52 pm
by CrackedP0t
Alright, I think I fixed it.
The problem was caused by me switching the two numbers inside and outside the rand() function. You'll still want to play with them, though, as t robots have a tendency to appear on the right.
Re: random
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
Posted:
Mon Feb 17, 2014 8:00 pm
by barney12345
Thanks for that, +2
Re: random
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
Posted:
Mon Feb 17, 2014 8:03 pm
by barney12345
Just one more thing sorry, is there a way to stop them being made on screen?
PS: I will definitely give u credit at the end of this game
Re: random
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
Posted:
Tue Feb 18, 2014 7:30 am
by CrackedP0t
Yeah, just change the Y numbers.
- Code: Select all
//Between -500 and 500:
rand(500 * 2) - 500;
//Between 0 and 500:
rand(500);
//Between 250 and 500:
rand() % 250 + 250;
//That is, rand() modulo (%) the range you want plus(+) the base
//Between -250 and -500:
(rand() % 250 + 250) * -1
//Between -250 and 500:
rand() % 750 - 250
Just substitute your numbers for the multiples of 250 in the examples.
P.S. The random numbers go in the Y argument of the CreateActor function in the actor that makes the bad guys.
Re: random
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
Posted:
Tue Feb 18, 2014 7:54 am
by barney12345
Thanks, but that still doesn't stop the creation of actors on screen
Im sorry if this is getting really annoying trying to answer such dumb questions
Re: random
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
Posted:
Tue Feb 18, 2014 8:06 am
by CrackedP0t
Oooohhh... OK.
Make another int variable, called badguyscanspawn or something.
Initialize it to 1.
In the bad guy maker, add
- Code: Select all
if (badguyscanspawn == 1 && badguycount < 3)
to the script. When you want the bad guys to not spawn, set badguyscanspawn to 0.
If you want to destroy all the bad guys at the same time, put in their Draw Actor event:
- Code: Select all
if (badguyscanspawn == 0) DestroyActor("Event Actor");
That should do it!
P.S. I don't mind in the
slightest helping you! I'm just glad I can help.
![Very Happy :D](http://game-editor.com/forum/images/smilies/icon_biggrin.gif)