• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

YoYo Tutorial Feedback: Intermediate -> Scripting

G

GrayDwarf

Guest
In the example code provided, there is a while loop which ends up in an infinite loop because it's missing an "exit". The game quietly hangs and it's not an easy thing to troubleshoot so new GameMakers will likely get hung up on it.

The problematic example code is on page 7 of 7.
Code:
   // Easy difficulty (or no move on other difficulties) forces the PC to place randomly

    while(true){
       var i = irandom(2);
       var j = irandom(2);
       if (!gameCell[i, j].occupied){
          scrUseCell(i, j, sprCross);
          }
       }
    }
The fixed code which allows the game to run and work as expected.
Code:
   // Easy difficulty (or no move on other difficulties) forces the PC to place randomly
    while(true){
       var i = irandom(2);
       var j = irandom(2);
       if (!gameCell[i, j].occupied){
          scrUseCell(i, j, sprCross);
          exit; // <-- MISSING LINE
          }
       }
    }
Another minor issue is on page 6 of 7. On ln 1, scrCheckGameresult should be scrCheckGameResult.
Code:
switch(scrCheckGameresult()){
    case boardState.NoResult:
       if gameTurn == gameTurnPlayer{
          gameTurn = gameTurnPC;
          }
       else {
          gameTurn = gameTurnPlayer;
          }
       break;
    case boardState.Winner:
       if gameTurn == gameTurnPlayer{
          currentGameState = gameState.YouWin;
          show_message_async("You WIN!");
          }
       else {
          currentGameState = gameState.YouLose;
          show_message_async("You LOSE!");
          }
       break;
    case boardState.Stalemate:
       currentGameState = gameState.StaleMate;
       show_message_async("DRAW!");
       break;
    }
 
Top