Internet计算机- Matoko打印指令未打印到终端



我是互联网电脑新手。我在Visual Studio中编写了以下代码:

import Debug "mo:base/Debug";
actor DBank {
currentValue = 300;
currentValue :=100;
Debug.print(debug_show(currentValue));
}

我输入,dfx start,启动服务器,得到消息

May 29 02:03:07.969 INFO Starting server. Listening on http://127.0.0.1:8000/*

然后打开另一个终端窗口,输入dfx deploy。但是,与服务器的终端没有显示currentValue(100)如我所期望的。

它没有显示您的值,因为您的代码中有错误,因此无法部署canister。

您需要首先将变量currentValue声明为mutable并声明其类型。

例如,你可以这样做:

import Debug "mo:base/Debug";
actor DBank {
var currentValue : Int = 300;
currentValue :=100;

Debug.print(debug_show(currentValue));

let hello : Text = "Hello world";
Debug.print(debug_show(hello));
}

这应该给你输出:

[Canister rrkah-fqaaa-aaaaa-aaaaq-cai] +100
[Canister rrkah-fqaaa-aaaaa-aaaaq-cai] "Hello world"

未正确初始化变量

import Debug "mo:base/Debug";
actor Dbank{
var currentValue = 300;
currentValue := 100;
Debug.print(debug_show(currentValue));
}

最新更新