Confused about instance variables

BlitzMax Forums/BlitzMax Beginners Area/Confused about instance variables

BlitzMax looks like lots of fun, but I'm getting confused about how instance variables work in BlitzMax. This snippet of code isn't doing what I expect:

---
Type Foo
Field bar:String;

Function Report()
Print(bar)
EndFunction

EndType

Local a:Foo=New Foo
a.bar="Hello World"
a.Report();
---

I would expect to see "Hello World" printed, but instead I see "0". What gives?

Use a Method instead of a Function:
Type Foo
  Field bar:String

  Method Report()
    Print(bar)
  End Method

EndType

Local a:Foo=New Foo
a.bar="Hello World"
a.Report();


You should have Method Report(), not Function Report(). Your code as it is creates a local variable bar:Int in function report. This is why you should always use Strict or SuperStrict mode ;)

Method instead of Function makes perfect sense. Thanks for the help!