but the syntax is unfamiliar and confusing to me. If i understood how statements like
def random_target_actor(hp0 = false)
(if something is in parenthesizes does "==" mean the same as "=")
What you have there is a default value in the event that particular argument isn't passed a variable when it the method is called. In that particular example, you can call random_target_actor as it is, or random_target_actor(variable). Obviously with that you want a true or false value passed in (so, random_target_actor(true) or random_target_actor(false)). It isn't a check to see if something equals it or not.
Basically, you can read it is:
The variable hp0 implicitly contains the object false unless I am explicitly told otherwise, in which case hp0 is of the passed in object.
The problem you get with these, though, is that Ruby doesn't assign the usual types to variables. There's not such thing as INT, BOOLEAN or CHAR variables. They are all objects. Even true or false are objects (of the TRUECLASS and FALSECLASS objects respectively). So you need to be careful. You could easily pass random_target_actor an integer or a string and it will be happy enough. It is a good idea to check that the argument taken is either a true or false value and flag up an issue if its neither of those.
and
return random_target_actor(true)
(wait.. what's true?)
'true' is the object value (remember, true is an inbuilt object of the type TRUECLASS) so what you are doing is returning the result of the method random_target_actor where hp0 (in the method random_target_actor) is given the value of true. It's almost as if the method was random_target_actor(hp0 = true) instead of hp0 = false.
So, basically, what true is, is the given value of hp0 at the time that method is invoked.
worked, and finally, this one...
if (not hp0 and actor.exist?) or (hp0 and actor.hp0?)
which loses me completely because I thought hp0 WAS actor.hp0?,
then if i understood these things, I could probably add in the exceptions for ghost/resolve/willpower.
I don't know what the method actor.hp0? returns so it's hard to really know whether they are the same or not. Usually, a method with the '?' at the end signals to the programmer that the value returned will be a true or false value. Because of the way that it is used I can assume this is the case here.
So, what we are asking in our condition is this:
if (not hp0 and actor.exist?) or (hp0 and actor.hp0?)
The first pair of parenthesis:
not hp0 : is another way of saying hp0 == false
actor.exist? : checks if our actor actually exists in the first place.
Together this is:
hp0 was given a false value and our actor exists.
The second pair:
hp0 : is another way to say hp0 == true
actor.hp0? : logic would assume it means does the actor have 0 HP left? (true or false)
so together that is:
hp0 was given the value true and the actor has 0HP left.
That statement as a whole, then:
IF
hp0 is false and the actor exists?
OR
hp0 is true and the actor's HP is 0
THEN do whatever...
I don't know how much that'll help, but that's what is going on there.
It sounds like you're having fun with this. It also seems like it might have benefited from a bit of planning out (I don't know how much you might have done, so I like to assume none).
I'm guessing that the problem is centred around the default system of "HP=0 means death and game over" business? If so, it might have been worth thinking of an alternative that left "HP=0 means death and game over" by implementing a second kind of HP that is used up first and leaving the default HP version for the ghost world (which I assume dying in there really is death and thus the rule "HP=0 means death and game over" remains true as opposed to what you have).
Perhaps if you write up a proper concept and goal thing, as well information on what the stats are and how they are used/depleted etc, I can maybe help work something out.