Returning objects
BlitzMax Forums/BlitzMax Programming/Returning objects
| ||
I've written the following method as part of my class:Method addLayer(id:String) Local layer: mapLayer = New mapLayer.Create(id,Self.width,Self.height); layer.id = id; 'For Local rep:Int = 1 To 20 ' layer.map[Rnd(Self.width),Rnd(Self.height)] = Rnd(1,3); 'Next ListAddLast Self.layers,layer; Return layer '-- allow layer object to be manipulated after creation End Method You will see that I'm trying to return the created 'layer' object, but BlitzMax keeps telling me 'Function can not return value' - however, layers definately an object and works with everything else. Does anyone know why this is? |
| ||
Shouldn't that be Method addLayer:mapLayer(id:string) ? |
| ||
Like what Gfk says. If you want a method to return something, you need to tell it what you want to return... in the same style you use for saying what Type a variable is. |
| ||
Thanks guys. I'm slowly getting there in picking up BlitzMax :-) |
| ||
Interesting, reading the "Functions" bit out of the documentation... It ReturnType is omitted, the function defaults to returning an Int ...except of course if you use SuperStrict, where you need to define the return type if you intend returning something. Other than that, the section on Functions isn't too bad - if a little light on examples... ;-) |