Can't understand code

I’ve recently found out about this framework and have started to modify the default mining bot a bit. Although I am a bit familiar with coding, there’s a bit I don’t understand in the code.

The variables (bools) for checking if the pilot is in danger (like when the shield is low) are like way down in the script and not part of any class or function. Nonetheless they are ran just fine. I seem to be missing how c# works. Does it like constantly evaluate all code inside the script or something?

Thanks in advance

At the risk of sounding stupid…
IIRC The bools are in the global namespace so they are available to all classes/functions in the script.
Variables are generally scoped (limited in visibility) into classes/functions so you don’t have unintended consequences
like this function changing the value while another function is needing it.

Hope this helps some.


Thanks for the reply. I get that variable could be in the global namespace and may be declared at runtime. What I don’t get is how the variables values are changing even though they are not visited when stepping through the script with the debugger.

For example line 110 in the mining script sets the bool which detemines if the bot should go into defence mode. In the script there’s 2 checks which check if this bool is set to true. So I’m really wondering how this bool is set to true (once the thresholds have been reached) without the script ever visiting that part of the code.

I looked it up on github, this is the line in the code:

Here is what I read from the C# code:
This line declares a property called ShieldHpPercent with only a getter function. This C# specific terminology aside, you can view it as just a function. This means, when ShieldHpPercent is used in an expression somewhere else, this results in a function call.
An example of this can be seen on the following lines:

As you can see in the example above, the function call for a property is coded without parenthesis, so its less obvious that it is a function call.

For more background on this, I recommend the following documentation:

Ah so this is it. I was looking at it like it was a variable declaration, but it’s actually a function. That explains it. Thanks