【问题标题】:Game maker language - Loops游戏制作者语言 - 循环
【发布时间】:2014-11-09 20:03:30
【问题描述】:

正在开发一个假设循环并显示 13 次的程序。这是我的代码

 { 
var count; 
var user_Input;
var output_msg;
var cel;
count = 0;

   do 
      { 
        user_Input = get_integer("Temperature conversion","");
        count = count + 1;
        cel = user_Input * 9/5 +32;
        user_Input = user_Input +10;
        output_msg =(string(count) + "Celsius" + string(user_Input) + " = Farenheit " + string(cel));
        show_message(output_msg);
        } 
         until (count == 13)

 }

它的作用是每次我按 Enter 时显示循环,而不是一次显示所有 13 个,如果我输入 10,例如每次循环它假设从最后一个循环添加 10。

例如。 1. 摄氏 10 = 华氏(在此处回答)
..... 2. 摄氏 20 = 华氏 (在此回答)
......13. Celsuis 130 = Farenheit ""
如果有人能带我走过并帮助我,那就太好了

【问题讨论】:

  • user_Input = get_integer(...); 行移到循环外

标签: loops gml


【解决方案1】:

你要做的是:

  1. 将对话框show_message 移出循环,准确地说,是在Do 循环之后。然后,它只会在循环结束时显示,而get_integer 对话框当然会等待用户输入一个值。
  2. get_integer 也移到循环之外,就在它之前。用户只需输入一次值。如果将其放入循环中,系统会要求您输入第 13 次值...
  3. 将结果计算附加到要显示在output_msg 中的消息到本身,并在末尾添加换行符"#"

{
    var count = 0;
    var user_Input;
    var output_msg = "";
    var cel;
    count = 0;

    user_Input = get_integer("Temperature conversion","");
    do
        {
        count = count + 1;
        cel = user_Input * 9 / 5 + 32;
        user_Input = user_Input + 10;
        output_msg = (output_msg + string(count) + ". Celsius" + string(user_Input) + " = Farenheit " + string(cel) + "#");
        }
    until (count == 13)
    show_message(output_msg);
}

为了清楚起见,我已经初始化了一些变量的初始值。

您的问题不是代码问题,而是逻辑问题(换行除外)循环中的所有内容,(Do,While)将在每次迭代时执行。如果您不想执行某些操作,则必须将其移出循环(之前/之后),或者使用条件检查。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-12
    • 1970-01-01
    • 2020-12-07
    • 1970-01-01
    • 1970-01-01
    • 2014-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多