Probably dumb question..

Monkey Forums/Monkey Beginners/Probably dumb question..

Jello Fox(Posted March) [#1]
I am running into another issue of "ok I used to do this like this, now how does it work here?". This is involving Class's and Methods..

My example to explain my problem is below.

In bitz basic or plus or 3d I would use a type and a function in this way.

function whatever(obj.obj)
for obj.obj=each obj
if obj\hp<0
end function

function Objectnull(obj.obj)
end function

and in monkey X it looks like this

method whatever()
for local objects:obj = eachin objects
if objects.hp<0

method objectsnull()

I need to know how to make this work, so that the method objectsnull() will have access to the last selected or currently selected obj in the objects:list.. I use this coding style allot, putting certain bits of code in another function and calling only when needed to effect an existing object.

Can someone help me?

Gerry Quinn(Posted March) [#2]
You can make ObjectNull a fubction that takes an object as parameter, or you can make it a method of Object:

Jello Fox(Posted March) [#3]
Thank you! I will try this out and see if I can make it work. Is there any certain place where I have to declare the function? I've noticed allot of context sensitive issues with this new compiler.. I mean it makes sense, its just not that well explained to me..

Either that or I'm missing allot of what would otherwise teach me these things.. I mean when I learned blitz Basic I learned from clear cut examples that taught me when , how , and how not to use code.. I just haven't seen as much of an explanation this time around for everything from arrays to class..

Gerry Quinn(Posted March) [#4]
A method is declared inside a class definition.

A function can be declared either inside or outside a class definition. If inside, it needs to be qualified by the class name if used from outside the class; don't worry about functions like this until you have a reason to use them. If outside, it's just an ordinary function, like so:

You could use either Kill or KillMe to achieve the same effect, as in my previous post.

Jello Fox(Posted March) [#5]
Thank you! I had played around with it again and did a work around, but I use functions allot in this way, separating out repeated commands so I can just reference them when needed.

I believe I now understand how to use this code.. Thanks again!