New Locations Set

Learn how to add a new set of locations.

1. Add locations in game.js

To set up a location we will need to do almost the same thing as setting up characters but we’re going to use Location functions instead. So we first go into our game.js file and use an addLocations function in the

init() {
	g.addLocations(safeZone);  
}

Then, still in the game.js file in the create function we will use a getLocations function functions.

create() {
	g.getLocations(safeZone);  
}

2. Add locations in the room.js

Then we will move into our room.js file in our onInit method and use a setupLocations function.

onInit() {
	g.setupLocations(safeZone);  
}

Now we can use a createLocations function anywhere in our room.js in this example we are just going to create a location at the beginning of our game in the onInit method as well under the getLocations function.

onInit() {
	...
	g.createALocation('safeZone', g.nextLocationId('safeZone'), { x: -47, y: 1940, width: 670, height: 100 }, '6cdc00', player => {  
		player.safe = true;  
	})
} 

For this example it could make all players that are standing in this location be safe from getting killed.

Now we will go into our onUpdate method in the room.js file and add a handleLocations function. This will make our Location start working for a certain type of characters.

onUpdate() {  
	g.handleLocations('safeZone', 'players');  
}

Need Help?

Proofread your code, check with your team and classmates, and if you’re still stuck!

Join us on Google Meet