Tictactoe 遊戲意外結束輸入期待 IF MySQL (Tictactoe game Unexpected end of input expecting IF MySQL)


問題描述

Tictactoe 遊戲意外結束輸入期待 IF MySQL (Tictactoe game Unexpected end of input expecting IF MySQL)

我正在為井字遊戲創建一個觸發器,用於檢查玩家或計算機是否獲勝。我相信我的編碼是正確的,但最後它說“語法錯誤,意外的 end_of_input,期待 IF”我的分隔符編碼正確,但這似乎是問題所在。這是代碼:

 delimiter //
create trigger check_winner
after update on grid
for each row

begin
declare message varchar(100);

select A into @A1 from grid where ttt = 1;
select A into @A2 from grid where ttt = 2;
select A into @A3 from grid where ttt = 3;
select B into @B1 from grid where ttt = 1;
select B into @B2 from grid where ttt = 2;
select B into @B3 from grid where ttt = 3;
select C into @C1 from grid where ttt = 1;
select C into @C2 from grid where ttt = 2;
select C into @C3 from grid where ttt = 3;


‑‑ Horizontal wins
    if @A1 = @B1 and @B1 = @C1 then     
        set message = concat('Player ', @A1, ' is victorious!');
        signal sqlstate '42000'
        set message_text = message;


   else if @A2 = @B2 and @B2 = @C2 then     
        set message = concat('Player ', @A2, ' is victorious!');
        signal sqlstate '42000'
        set message_text = message;


   else if @A3 = @B3 and @B3 = @C3 then     
        set message = concat('Player ', @A3, ' is victorious!');
        signal sqlstate '42000'
        set message_text = message;


‑‑ Vertical wins
    else if @A1 = @A2 and @A2 = @A3 then     
        set message = concat('Player ', @A1, ' is victorious!');
        signal sqlstate '42000'
        set message_text = message;

    else if @B1 = @B2 and @B2 = @B3 then     
        set message = concat('Player ', @B1, ' is victorious!');
        signal sqlstate '42000'
        set message_text = message;

    else if @C1 = @C2 and @C2 = @C3 then     
        set message = concat('Player ', @C1, ' is victorious!');
        signal sqlstate '42000'
        set message_text = message;

‑‑ Diagonal wins
    else if @A1 = @B2 and @B2 = @C3 then     
        set message = concat('Player ', @A1, ' is victorious!');
        signal sqlstate '42000'
        set message_text = message;

    else if @A3 = @B2 and @B2 = @C1 then     
        set message = concat('Player ', @A3, ' is victorious!');
        signal sqlstate '42000'
        set message_text = message;

‑‑ Game continues
    else 
        set message = 'Game is still ongoing';
        signal sqlstate '42000'
        set message_text = message;

end if;

end// ‑‑ error is right here

任何幫助都會有所幫助!


參考解法

方法 1:

Change your

else if 

to

elseif

i.e. remove the space between the else and if.

(by RyuKaze78Kabir)

參考文件

  1. Tictactoe game Unexpected end of input expecting IF MySQL (CC BY‑SA 2.5/3.0/4.0)

#tic-tac-toe #MySQL #Triggers #syntax






相關問題

為什麼我的遞歸沒有返回但最終導致堆棧溢出? (Why does my recursion not return but end up in a stack overflow?)

重新開始遊戲 (Restarting a game)

沒有人工智能的井字遊戲 (Tic-Tac-Toe without AI)

Tictactoe 遊戲意外結束輸入期待 IF MySQL (Tictactoe game Unexpected end of input expecting IF MySQL)

如何在第一次和第二次觸摸時執行不同的事件(TicTacToe for Android) (how to do different event on first and second touch (TicTacToe for Android))

TicTacToe Python 檢查獲勝者 (TicTacToe Python Check for Winner)

使用 Java 可定制的井字遊戲板 (Customizable TicTacToe game board with Java)

我的井字遊戲理論上是個大問題,但對我來說一切似乎都很好 (Theoretically big problem with my Tic tac toe game , but for me all seems good)

遊戲線程問題 (Issues with threads in game)

我在使用 Turtle 圖形檢查井字遊戲中的獲勝者時遇到了一些問題 (I am having some problems checking the winner in a tic tac toe game using Turtle graphics)

為什麼我選擇第一個位置後立即收到勝利信息 (Why do i get the victory message right after choosing the first position)

如何修復此井字遊戲的未捕獲參考錯誤 (How do I fix an uncaught reference error for this TicTacToe)







留言討論