# Logic

3 replies to this topic

### #1 Cuata

Cuata

GMC Member

• New Member
• 12 posts
• Version:GM8

Posted 03 February 2012 - 02:56 AM

i am making a game that has a theme of hospital. the patients will need either injection or medicine. how can i make the patients randomly ask for injection or medicine?

here are my codes so far

obj_patient1

create
```timeWaited = 0;
severityOfInjury = irandom_range(1, 10);

priority = timeWaited *  (severityOfInjury / 3);

alarm[10] = room_speed;
```

alarm
```timeWaited += 0;

priority = timeWaited *  (severityOfInjury / 3);

alarm[10] = room_speed;
```

step
```var xx,yy,xxx,yyy;

if instance_exists(obj_wait)
{
xxx=64;
yyy=336;
xx=floor(xxx+10);
yy=floor(yyy+10);
}
```

obj_doc

step
```if (instance_exists(obj_patient1))
{
var nextPatient, highestNeed;
nextPatient = noone;
highestNeed = 0;

with (obj_patient1)
{
if (highestNeed > other.highestNeed)
{
other.nextPatient       = id;
other.highestNeed  = highestNeed;
}
}

nextPatient.selected = true; // Or whatever you're way of selecting them is :)
}
```

• 0

### #2 drt_t1gg3r

drt_t1gg3r

GMC Member

• GMC Member
• 3230 posts
• Version:Unknown

Posted 03 February 2012 - 09:04 AM

create event
treatment = choose( choiceA, choiceB);
• 0

### #3 Incon

Incon

GMC Member

• GMC Member
• 190 posts

Posted 03 February 2012 - 01:57 PM

Might be offtopic, but:

timeWaited = 0;
severityOfInjury = irandom_range(1, 10);

priority = timeWaited * (severityOfInjury / 3);

alarm[10] = room_speed;

alarm

timeWaited += 0;

priority = timeWaited * (severityOfInjury / 3);

alarm[10] = room_speed;

btw: red code causes blue code to always be 0
The second one should be +=1;

severityOfInjury = irandom_range(1, 10);

severityOfInjury = round(random(10)); might be better for performance

if (instance_exists(obj_patient1))
{
var nextPatient, highestNeed;
nextPatient = noone;
highestNeed = 0;

with (obj_patient1)
{
if (highestNeed > other.highestNeed)
{
other.nextPatient = id;
other.highestNeed = highestNeed;
}
}

nextPatient.selected = true; // Or whatever you're way of selecting them is
}

Orange code is calling a variable that doesnt exist: highestNeed on obj_patient
Should be:

if (priority > other.highestNeed)

other.highestNeed = priority;

var nextPatient, highestNeed;

Might be worth giving temporary variables a different name so you know that they only exist there. Like _nextPatient and _highestNeed. Same goes for globalvariables, giving them a name like g_(name) helps to identify them later.

Hope this helps

Edited by Incon, 03 February 2012 - 01:58 PM.

• 0

### #4 _250968

_250968

GMC Member

• New Member
• 28 posts

Posted 04 February 2012 - 05:09 PM

what i would do is this
```switch(irandom_range(1,2))
{case 1:  injection
case 2:  medicine }
```
but the choose function works too!(and much easier)!
• 0

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users