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

时间:2016-03-05 14:43:37

标签: game-maker

MHS读者留言:请勿复制此代码。只需用它来帮助你。

我从文件中加载10个单词,然后在网格中显示9个单词。 30秒后移除1并放入文件中的第10个单词。然后要求用户猜测这2个单词。他们每人有3次机会。当我输入正确的答案时,它仍然说我弄错了。我甚至得到了正确的答案,以协助测试。结果总是错误的。

这些是脚本: ReadFile的

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);

DrawWords

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
        }
    }

NewGrid

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);

检验字

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;                        
    }

DrawCheck

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);

1 个答案:

答案 0 :(得分:0)

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

ABOUT(ASCII代码:97,98,111,117,116)

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

它将返回false

因此您需要更改

Fread = string_upper(file_text_readln(Fopen));

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