Here's my main.js.
function Move(name, inputs) {
if (!IsCommandQueueEmpty(name)) return;
if (IsKeyPressed(inputs.up)) QueuePersonCommand(name, COMMAND_MOVE_NORTH, false);
else if (IsKeyPressed(inputs.down)) QueuePersonCommand(name, COMMAND_MOVE_SOUTH, false);
else if (IsKeyPressed(inputs.left)) QueuePersonCommand(name, COMMAND_MOVE_WEST, false);
else if (IsKeyPressed(inputs.right)) QueuePersonCommand(name, COMMAND_MOVE_EAST, false);
}
var inputs = [];
inputs[0] = { up: KEY_UP, down: KEY_DOWN, left: KEY_LEFT, right: KEY_RIGHT };
inputs[1] = { up: KEY_W, down: KEY_S, left: KEY_A, right: KEY_D };
inputs[2] = { up: KEY_U, down: KEY_J, left: KEY_H, right: KEY_K };
inputs[3] = { up: KEY_NUM_8, down: KEY_NUM_2, left: KEY_NUM_4, right: KEY_NUM_6 };
var players = ["player1", "player2", "player3", "player4"];
function Update() {
for (var i = 0; i < players.length; ++i) {
Move(players[i], inputs[i]);
}
function setPlayerPos() {
SetPersonXYFloat("player1", 32, 32);
SetPersonXYFloat("player2", 32, 128);
SetPersonXYFloat("player3", 128, 32);
SetPersonXYFloat("player4", 128, 128);
}
function game() {
CreatePerson("player1", "spWar.rss", false);
CreatePerson("player2", "spWar.rss", false);
CreatePerson("player3", "spWar.rss", false);
CreatePerson("player4", "spWar.rss", false);
QueuePersonScript("player1", "setPlayerPos();", true);
QueuePersonScript("player2", "setPlayerPos();", true);
QueuePersonScript("player3", "setPlayerPos();", true);
QueuePersonScript("player4", "setPlayerPos();", true);
SetUpdateScript("Update()");
MapEngine("testmap.rmp", 60);
}It runs fine. However, if I edit it in any way, then revert it back to EXACTLY what you see above, even if I freshly copy-paste, I start getting stupid errors.
First I'll get "missing } after function body line 44"
If I add a } to the very end of the code, I'll then get
"Reference error game is not defined."
Really?
Game is not defined?
Any possible idea what's going on?
When I first used Sphere I'd do the same thing. I'd curse the screen for wondering why, then see my error moments later. Just to know I had a pretty rocky relationship with my monitor the first few months. :P (But that was so long ago)...
I...actually can believe I missed that. Thanks. And double thanks for the explanation. I see what happened now.
So strange, though, 'cause I don't remember deleting that curly bracket.
It's Radnen's code. I just copy-pasted it, heh. I typically indent differently than most people (I find standard indentation difficult to read), which is perhaps why I didn't see the error.
I curse the screen, then give up and walk away, heh. I'll get there, though.
So long as you can read it, and the intent is clear to you, indent however makes you comfortable :)