在 GameMaker 中输入检查的结果不正确

Incorrect result to input checking in GameMaker

致 MHS 读者的消息:请勿复制此代码。只需使用它来帮助您。

我从一个文件中加载了 10 个单词,然后在网格中显示了 9 个单词。 30 秒后,1 被删除,文件中的第 10 个单词被放入。然后要求用户猜测这 2 个单词。他们每人有3次机会。当我输入正确答案时,它仍然说我做错了。我什至让它画出正确的答案来协助测试。结果总是返回错误。

这些是脚本: 读取文件

global.DelWord = "Unknown";
randomize();                                                               
Fopen = file_text_open_read(working_directory + "\Words.txt");    
global.WordList = ds_list_create();
global.FileLen = file_text_eof(Fopen);
while(!file_text_eof(Fopen)){
    Fread = string_upper(file_text_readln(Fopen));
    ds_list_add(global.WordList,Fread);
    }
file_text_close(Fopen);
ds_list_shuffle(global.WordList);
global.WildCard = ds_list_find_value(global.WordList,global.FileLen);
ds_list_delete(global.WordList,global.FileLen);

画字

z=0;
draw_set_colour(c_black);
draw_set_font(font0);
draw_set_valign(fa_left);
draw_set_halign(fa_bottom);
draw_text(100,100,"Code by kammak743);
draw_text(1600,900,string_lower(global.WildCard));
draw_text(1200,900,string_lower(global.DelWord));



for (x=0; x<3; x+=1){
    for (y=0; y<3; y+=1){
        draw_text((x*400)+700,(y*200)+290,ds_list_find_value(global.WordList,z));
        z=z+1
        }
    }

新网格

ds_list_shuffle(global.WordList);
global.DelWord = ds_list_find_value(global.WordList,global.FileLen);
ds_list_delete(global.WordList,global.FileLen);
ds_list_insert(global.WordList,global.FileLen,global.WildCard);
ds_list_shuffle(global.WordList);

CheckWords

Correct1 = 0;                                                        
OldWordA = false;                                                   
while (OldWordA == false) && (Correct1 <3){                      
    global.OldWordQ = get_string("What word was replaced?","");         
    if string_lower(global.OldWordQ) == string_lower(global.DelWord){  
        OldWordA= true;                                
        }
    Correct1 += 1;                                           
    }


Correct2 = 0;                                            
NewWordA = false;
globalvar NewWordA;
while (NewWordA == false) && (Correct2 <3){
    global.NewWordQ = get_string("What word is new?","");
    if string_lower(global.NewWordQ) == string_lower(global.WildCard){
        NewWordA= true;
        }
    Correct2 += 1;
    }


global.Win=false;
if (NewWordA == true) && (OldWordA == true){  
    global.Win=true;                            
    }
else{
    global.Win=false;                        
    }

绘图检查

if global.Win == true{
    draw_text(900,900,"You won!!!");
    }
else{
    draw_text(900,900,"You failed");
    }
draw_text(400,50,global.OldWordQ);
draw_text(900,50,global.NewWordQ);

您使用 file_text_readln() 从文件中读取单词,但此函数还读取 CR/LF 代码 ($0d, $0a),因此当您比较两个字符串时,例如

ABOUT(ASCII码:97、98、111、117、116)

ABOUT(ASCII码:97、98、111、117、116、13、10)

它将 return false

因此你需要改变

Fread = string_upper(file_text_readln(Fopen));

Fread  = string_upper(file_text_read_string(Fopen));
file_text_readln(Fopen);