1. Create your database
{
"rules": {
"gameid": {
".read": true,
".write": true
}
}
}
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.8.0/firebase-app.js";
import { getDatabase, ref, set, get, child, onValue } from "https://www.gstatic.com/firebasejs/10.8.0/firebase-database.js";
import { firemp } from "https://script-js.github.io/FireMP/main.js";
const firebaseConfig = <Your Firebase Config Variable>
// Initialize Firebase
const app = initializeApp(firebaseConfig);
firemp.registerFunctions(getDatabase, ref, set, get, child, onValue)
</script>
Used to start a new game
Example:
firemp.createGame(function(gameid) {
alert("Game ID: " + gameid)
})
Used to end the game
Example:
firemp.endGame()
Used to start the game
Example:
firemp.startGame()
Allows players to join the game
Example:
var playerName = prompt("Player Name")
var gameId = prompt("Game ID")
firemp.joinGame(gameId,playerName,function() {alert("Game Started")},function() {alert("Game Over")})
Allows a player to leave the game
Example:
firemp.leaveGame()
Listens for changes in a specified value
Example:
firemp.listen(<Value Name>,function(data) {alert("Value Data: " + data)},function() {alert("Value Non-existent")})
Add or update a game value
Example:
firemp.send(<Value Name>,<Value Data>)
Remove a game value
Example:
firemp.remove(<Value Name>)
Add or update player data
Example:
firemp.playerDataAdd(<Value Name>,<Value Data>)
Remove player data
Example:
firemp.playerDataRemove(<Value Name>)
Get a list of players in the game Fires every time the player list changes
Example:
firemp.getPlayerList(function(players) {
alert("List of Players" + players) // Outputs an array
})
Removes a player from the game
Example:
firemp.removePlayer(<Player Name>)