Confused about instance variables

BlitzMax Forums/BlitzMax Beginners Area/Confused about instance variables

patsplat(Posted 2007) [#1]
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?


GfK(Posted 2007) [#2]
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();



Otus(Posted 2007) [#3]
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 ;)


patsplat(Posted 2007) [#4]
Method instead of Function makes perfect sense. Thanks for the help!