How do you make an actor appear ramdomly on a region?

Game Editor comments and discussion.

How do you make an actor appear ramdomly on a region?

Postby ded15 » Sun Nov 16, 2008 5:46 am

I'd like to know how do you make an actor appear randomly on an entire game?
ded15
 
Posts: 1
Joined: Sun Nov 16, 2008 5:41 am
Score: 0 Give a positive score

Re: How do you make an actor appear ramdomly on a region?

Postby Kalladdolf » Sun Nov 16, 2008 10:47 am

On the create actor event put the following code:
Code: Select all
x = rand(200);
y = rand(200);


in this case, the actor will appear randomly between x 0 - 200 and y 0-200.
User avatar
Kalladdolf
 
Posts: 2427
Joined: Sat Sep 08, 2007 8:22 am
Location: Germany
Score: 120 Give a positive score

Re: How do you make an actor appear ramdomly on a region?

Postby Bee-Ant » Mon Jan 05, 2009 1:23 pm

That code will only work for any actor arround x 0-200 and y 0-200, what if you want to put your actor at x,y(500,1500)???
Use this code to make its appear randomly at any coordinate
Code: Select all
x-=rand(400);
x+=rand(400);
y-=rand(400);
y+=rand(400);

:D
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: How do you make an actor appear ramdomly on a region?

Postby DST » Tue Jan 06, 2009 12:19 am

x=rand(800)-400; :D

Go one step further, with a wireframe/filled region actor, script called from the wireframe/filled actor:

otheractorname.x=rand(width);

Many users don't realize, you can use the variables 'width' and 'height' for any actor. ( I don't think its mentioned in the documentation).
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: How do you make an actor appear ramdomly on a region?

Postby Bee-Ant » Tue Jan 06, 2009 12:31 pm

DST wrote:x=rand(800)-400; :D

Ah yes, thats what I mean...
you forgot something
Code: Select all
y=rand(800)-400;
:P
using width just move that actor as far as it's own width...
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron