Please explain an error? This block cannot be in a definition

I’m getting an error I don’t understand. The attachments show it clearly.
I create a Global Variable BlockH And set it to a simple equation,
If I use BlockH In another equation I get a red cross error,
If I replace BlockH with the original equation I don’t get any error.
I cannot find any deffinition of the error. Please advise.
blocks (Initialize BlockH)
blocks (Get BlockH {ERRORs})
blocks (Get BlockH {ERRORs})

Did You click on red X ?

Follow these steps to remove the error,

  1. Initialize global variable with a constant, not with an equation.
  2. Then Set that global variable with an equation in Screen1.Intialize event.

Keep koding…
All the best.

3 Likes

The variable does not yet exist … and doing math operations … it is not right …

1 Like

The error occurred because the program doesn’t know which variables needs to be initialized first. It cannot find the other variable. So follow what @Automate_My_Project said.

Yes , I said too …
I suggested that he click on the red X to see if he reading the error message, came to that conclusion.

1 Like

How silly of me.
It displays: This block cannot be in a definition
But I don’t understand this message.
If I take the ‘Get’ out of the equation and simply use it to initialized a global variable. I get the same error. But surely that is the very point of a ‘Get’ block?

Friend, first try to initialize your numeric variable. Then do the mathematical operation.
Try :
First use initialize block , Second use Set block with mathematical operation.

1 Like

Set the blocks as this;

1 Like

Thank you so much.
Now that the error is gone, I think I can see the logic. One must first initialize a global. So the compiler can have created an instance of it before it is fully available for use. Indeed one does not even need to assign any value to the initialize, simply including the block is enough. So empty black is enough.global_declaration I have been coding on and off for more than 40 years. And leaving unassigned variables it bad practice. However, It seems to me that this is not particularly intuitive. Could a Declaration block be added to the variables blocks? It would simply be a block that takes no inputs and is a standalone block, containing no sub-blocks.Declaration of
Anyway, Thank you for your help.
One last question, if I may,. Is there a place where suggestions for Kodular be discussed?

2 Likes

@Julian, Glad you solved it. Then check the solution to help others. About the other doubts, you research if there is no equal subject in the community. If not, create one. I think it would be “discuss” and “I want”. hug

@Julian totally agreed.

Thank You very much this worked . youre are briliant