Keep getting "Unexpected" SyntaxErrors

Discussion in 'Learning Javascript' started by Dinamic Creates, Jan 3, 2018.

  1. Dinamic Creates

    Dinamic Creates Project Stealth | Project Dungeon Trios Veteran

    Messages:
    69
    Likes Received:
    24
    Location:
    México
    First Language:
    Spanish
    Primarily Uses:
    RMMV
    Hello, I'm interested in making plugins, however, I'm working with events and script calls by now.
    I'm coding a script that enables or disables a Switch if the two nearest spaces behind the player are passable or not, but when I check if it works, the game keeps throwing me "Unexpected" SyntaxErrors.

    This is my first time doing something in Javascript. I have programmed in C# and Java, so I think I know what I'm doing with this script.
    I will appreciate it if anyone points me the issue in these.

    As a script call (where 3 is the Switch I want to manage):
    var AllowRegroup = false;
    var Direction = $gamePlayer.direction();
    var x = $gamePlayer.x;
    var y = $gamePlayer.y;

    switch (Direction)
    {
    default: break;
    case 2: AllowRegroup = $game_player.passable?(x,y-1,2) && $game_player.passable?(x,y-2,2); break;
    case 8: AllowRegroup = $game_player.passable?(x,y+1,8) && $game_player.passable?(x,y+2,8); break;
    case 4: AllowRegroup = $game_player.passable?(x+1,y,4) && $game_player.passable?(x+2,y,4); break;
    case 6: AllowRegroup = $game_player.passable?(x-1,y,6) && $game_player.passable?(x-2,y,6); break;
    }
    $gameSwitches.setValue(3, AllowRegroup);

    As a script call inside a condition
    $gamePlayer.direction() == 2 && $game_player.passable?($gamePlayer.x,$gamePlayer.y-1,2) && $game_player.passable?($gamePlayer.x,$gamePlayer.y-2,2) ||
    $gamePlayer.direction() == 8 && $game_player.passable?($gamePlayer.x,$gamePlayer.y+1,8) && $game_player.passable?($gamePlayer.x,$gamePlayer.y+2,8) ||
    $gamePlayer.direction() == 4 && $game_player.passable?($gamePlayer.x+1,$gamePlayer.y,4) && $game_player.passable?($gamePlayer.x+2,$gamePlayer.y,4) ||
    $gamePlayer.direction() == 6 && $game_player.passable?($gamePlayer.x-1,$gamePlayer.y,6) && $game_player.passable?($gamePlayer.x-2,$gamePlayer.y,6)

    Thanks for your time and sorry for my english if something is wrong.
     
    #1
  2. Shaz

    Shaz Veteran Veteran

    Messages:
    37,553
    Likes Received:
    11,263
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    I doubt this is causing the problem, but variable names should begin with a lower case character.

    $game_player.passable?(x, y, direction) is from VX Ace. It is $gamePlayer in MV, not $game_player. And I think it is .canPass(x, y, dir), not .passable? You've got it wrong on all of those lines.
     
    #2
  3. Dinamic Creates

    Dinamic Creates Project Stealth | Project Dungeon Trios Veteran

    Messages:
    69
    Likes Received:
    24
    Location:
    México
    First Language:
    Spanish
    Primarily Uses:
    RMMV
    It worked! Thank you very much.
    That makes a lot of sense. It seems I didn't noticed that on my research.
     
    #3
  4. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,556
    Likes Received:
    977
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    If you were wondering more about why it gave that error specifically - the "?" in JavaScript is reserved for the Conditional Operator which is a ternary operator. Ternary operators expect 3 arguments which is why it was confused by the ";" that ended the statement.
     
    #4

Share This Page