i'm making a game that has multiple hotspots and i want to randomly set an object on one of them. i got it to work but sometimes the objects overlap each other. i was wondering if anyone knows how to prevent this?
i want it so you click one hotspot and it sets an object there, then it randomly places another object on one of the other hotspots. but it has been going over the first object.
Are you aware of the option to set a baseline for objects? this way you can define which object is the front one, when two objects overlap?
well yeah but it's a none player game. like the only thing used is objects and hotspots. so it's like once you click on the hotspot it needs to be off and no randomly put object can go there. i have been messing around with the
if(ObjectsCollide(0,5){
int ran=Random(7);
if(ran=0){
;move the object elsewhere
}
}
don't critisize my scripting there cause i no it's wrong. i don't have the script with me at the moment so it's not rite.
but is there anyway to do this withought the tedious long repetetive script?
cause there's 9 hotspots and like 8 of the above script(in more detail) per hotspot.
Couldn't you just create an array of ints and once an item is put there set the value to 1, then before you place the next object, see if the corrisponding hotspot already has an object on it if not pick a new random number... just code off the top of my head but...
int objPlaced[8];
int counter;
int ran;
while (counter < 7) {
ran = Random(7); //pick a random number
if (objPlaced[ran]==0) { //if the object hasn't been placed yet place it
//Placement of object code here
objPlaced[ran] = 1;
}
else { //if the object has been placed
while (objPlaced[ran]==1){ //Until you find a unused number loop
ran = Random(7);
if (objPlaced[ran] == 0){
//Place object
objPlaced[ran] = 1;
}
}
counter++;
}
Ok not tested... maybe needs to be tweeked some... but like I said off the top of my head with not much thought to it.
that sounds like an easier way but unfortunately i have no idea on how to script it using those commands. if your willing to show me i'll incude your name in the credits.
Well, you should just place the code Alynn provided on player clicking over a hotspot. The local on_mouse_click function should be suitable to handle that event:
//room script
function on_mouse_click() {
if (GetHotspotAt(mouse.x, mouse.y)>0) {
// place Alynn's code here
}
}
Quote from: Pie-rat on Mon 26/07/2004 18:09:42i want it so you click one hotspot and it sets an object there, then it randomly places another object on one of the other hotspots. but it has been going over the first object.
The code can even be simplier if it's a matter of just two objects:
//room script
int isPlaced = 0;
function on_mouse_click() {
int hotspot = GetHotspotAt(mouse.x, mouse.y);
if ((isPlaced==0) && (hotspot>0)) {
ObjectOn(FIRST_OBJECT);
SetObjectPosition(FIRST_OBJECT, GetHotspotPointX(hotspot), GetHotspotPointY(hotspot));
int ran = 1 + Random(8);
while (ran == hotspot) ran = 1 + Random(8);
ObjectOn(SECOND_OBJECT);
SetObjectPosition(SECOND_OBJECT, GetHotspotPointX(ran), GetHotspotPointY(ran));
isPlaced = 1;
}
}