Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(2 edits)

How does declaring variables inside functions work? Does this have scope? 

I read the docs but I am a bit confused about storage classes? 

Take the following example:

```

let global;

let #weakGlobal := 0;

inc() {

  let i;

  i++

}

main() {

  let a, b;

 global++;

  inc();

  int();

}

```

1. What value is `global` initialized with? 

2. Does `weakGlobal` ever go out of scope, since it is declared at the file level?

3. Does `i`'s value persist across function calls? What if it was weak? What if I did `let i = 1;` in there instead, would it keep resetting on calls of `inc`?
 4. Does `main` see the vars declared inside of `inc`? Or are they scoped to `onc`? Does `inc` see the vars inside `main`?

5. The documentation mention vectors but forgets to explain their syntax. Can you elaborate on that? 


Thank you!

I'd love to test all these questions out myself but the results seem "inconsistent" to me. You mention 3B being buggy in the docs. I'm not sure if it actually is being inconsistent/buggy or if I'm just not getting it. Hence, why I'm asking. 

PS: Your Discord link is broken. 


Great work! I'm really enjoying playing around with this. It's awesome stuff! 

Hello! I’m glad you enjoyed my FC!

To be honest, I barely remember all the things, so will try to answer as I remember.

  1. Zero. At least this is the most logical answer I can give, because all values are 3-bit unsigned integers
  2. As I rememver, weak variables were made for local use in function. It means that you have two types of variables: strong and weak. Strong have always defined in 32 cell memory, so one cell is always “booked” for it. Weak variables are defined from the other side of memory, and can be redefined in function calls inside function. Example: fn1() { let #weak1 = 0; } // weak1 address is 31 fn2() { let #weak2 := 4; fn1() } // weak2 address is 31, so in the end it can become 0, not 4 This is how I remember it should work
  3. As I remember it shouldn’t persist. Actually, if you open developer’s console on this site, every time you run program, you’ll see all assembly code generated, and how compiler parsed it all. I think it could help you.
  4. No, they both don’t see variables of each other
  5. “Vector” is an alias for array, so you define them: let vec[5], then use: vec[0] - first element, can be assigned

And yes, discord server is dead :(