Internet Computer - Matoko print instruction not printing to terminal

268 Views Asked by At

I am new to internet computer. I wrote the following code on Visual Studio:

import Debug "mo:base/Debug";

    actor DBank {
        currentValue = 300;
        currentValue :=100;

        Debug.print(debug_show(currentValue));
    }

I typed, dfx start, to start the server and got the message

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

And then opened another terminal window and typed, dfx deploy. But the terminal with the server doesn't show the currentValue (of 100) as I expected.

2

There are 2 best solutions below

0
On

It doesn't show your value due to the fact that canister can not be deployed as there are errors in your code.

You need to first declare your variable currentValue as mutable and declare its type.

For example you can try with this:

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

}

this should give you output:

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

You haven't initialized variable properly

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