Legacy GM Zombie Shooter I Zombies aren't spawning anymore

H

HypSandar

Guest
Hello

Here's the story:

[1] - Zombies spawning worked
[2] - Implemented changes, 30 ticks between spawns to polish it.
[3] - Zombies aren't spawning anymore



Here's the script:

Player
Code:
Information about object: obj_player
Sprite: Player
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:

No Physics Object
Create Event:

execute code:

//Variables
shooting=false;
health=100;

Alarm Event for alarm 0:

execute code:

shooting=false;

Step Event:

execute code:

image_angle = direction
image_angle = point_direction(x,y,mouse_x,mouse_y);

if keyboard_check(vk_right) && place_free(x+5,y) {x+=5}
if keyboard_check(vk_left) && place_free(x-5,y) {x-=5}
if keyboard_check(vk_up) && place_free(x,y-5) {y-=5}
if keyboard_check(vk_down) && place_free(x,y+5) {y+=5}

Mouse Event for Glob Left Button:

execute code:

if shooting=false
{
shooting=true
instance_create(x,y,obj_bullet)
alarm[0] = 30;
}

Bullet

Code:
Information about object: obj_bullet
Sprite: Bullet
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:

No Physics Object
Create Event:

execute code:

move_towards_point(mouse_x,mouse_y,15)

Zombie

Code:
Information about object: obj_zombie
Sprite: spr_zombie
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:

No Physics Object
Step Event:

execute code:

image_angle = point_direction(x,y,obj_player.x,obj_player.y)
mp_potential_step(obj_player.x,obj_player.y,3,false)

Spawner

Code:
Information about object: obj_spawner
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:

No Physics Object
Create Event:

execute code:

spawn=true

Alarm Event for alarm 0:

execute code:

spawn=true

Step Event:

execute code:


//Floor means its a whole number, NOT "1.5415", instead just "1"
// Picks a number from 0 to 80
// If that number happens to be less than 1, it will create a zombie
if floor(random(80)) < 1 && spawn = true
{
instance_create(x,y,obj_zombie)
}

spawn=false
alarm[0]=30

Thanks in advance! I've been trying to fix this for 2 hours straight....
 
Last edited by a moderator:
J

Jaqueta

Guest
Your "Spawn=false" and alarm[0]=30 are outside the brackets, this means that at the end of every step, it'll set spawn to false, and the alarm to 30.

Here's your solution:
Code:
if floor(random(80)) < 1 && spawn = true
{
instance_create(x,y,obj_zombie)
spawn=false
alarm[0]=30
}

//You can also use irandom to get a random integer, instead of flooring the random value, it's more optimal.
 

Phil Strahl

Member
Each step you set spawn to false and also reset the alarm to 30. That should go inside the spawning condition:
Code:
if floor(random(80)) < 1 && spawn = true
{
  instance_create(x,y,obj_zombie)
  spawn=false
  alarm[0]=30
}
 

Phil Strahl

Member
Your "Spawn=false" and alarm[0]=30 are outside the brackets, this means that at the end of every step, it'll set spawn to false, and the alarm to 30.

Here's your solution:
Code:
if floor(random(80)) < 1 && spawn = true
{
instance_create(x,y,obj_zombie)
spawn=false
alarm[0]=30
}

//You can also use irandom to get a random integer, instead of flooring the random value, it's more optimal.
Beat me to it ;)
 
H

HypSandar

Guest
Your "Spawn=false" and alarm[0]=30 are outside the brackets, this means that at the end of every step, it'll set spawn to
//You can also use irandom to get a random integer, instead of flooring the random value, it's more optimal.
[/CODE]
So i can just replace "floor" with "irandom" ?
 

Phil Strahl

Member
So i can just replace "floor" with "irandom" ?
Yes! :)

EDIT:
It's also good practice to wrap your if conditions in parentheses of boolean statements, in case you want to move on to other programming languages one day, like this:
Code:
if ((irandom(80) < 1) && (spawn))
{
  // stuff
}
Also note that in GML it's not necessary to type out whether something is true, you can test the variable itself. Also works with "false", e.g.


Code:
var condition = false;

if (condition)
{
   // this will execute if "condition = true"
}

if (!condition)
{
  // this will get executed if "condition = false"
}
 
Last edited:
H

HypSandar

Guest
And, you don't need to use <1, since it only returns integers, a simple irandom(80)==0 will do the same :v
I changed it to that and it caused an unknown error.
Code:
if irandom(80)==0 && spawn = true
Nevermind, fixed it.
Thanks for helping me out guys!
 
Last edited by a moderator:
Top