ID:149332
 
    ocean
icon_state = "sea"
Enter(mob/Player/M as mob)
if(M.onboat==0)
return 0
else
return 1

Works great! A player can't enter the ocean. Problem: The wave can't. Why is it trying to apply the mob/Player/M enter to Waves!?! My waves are a mob/Wave. Every time I get a 'M.onboat not defined'. A Wave doesn't have that var. Please help. Thanks in Advance
Nova2000 wrote:
>   ocean
> icon_state = "sea"
> Enter(mob/Player/M as mob)
> if(M.onboat==0)
> return 0
> else
> return 1
>

Works great! A player can't enter the ocean. Problem: The wave can't. Why is it trying to apply the mob/Player/M enter to Waves!?! My waves are a mob/Wave. Every time I get a 'M.onboat not defined'. A Wave doesn't have that var. Please help. Thanks in Advance

I believe Enter is taking the 'atom/Movable/O that gets passed to it, and is treating anything that gets passed as a /mob, because of the 'as mob'. I'm guessing it would treat objects the same way with this. Try:

ocean
Enter(atom/movable/O) // The default argument
if(istype(O, /mob/player)) //check to see if O is a player mob
var/mob/player/P = O //create a reference to a player mob, and assign O to it
if(!P.onboat) //If P is not on a boat
return 0 //Deny it entry
else
return ..() //Allow the default process to happen, in case some other code would deny access somewhere else in your code


sigh, dm tags made this a really wide message, so I took them out

In response to Flick
Thanks!
In response to Flick
Careful... that would still not allow the wave to Enter().

Observe the chain:
Enter(O is a player but not on a boat)
if(O is a player) //yep
P = O
if(P isn't on a boat) //yep -- we'll skip the next else
don't let him in //O can't enter

Enter(O is a player on a boat)
if(O is a player) //yep
P = O
if(P isn't on a boat) //nope, moving onto the else
else
let him in //O can enter

Enter(O is a wave)
if(O is a player) //nope, skipping if

//nothing happens! implicit 'O can't enter'
In response to Spuzzum
oops! I forget the ..() all the time. Drives me nuts. I really am a sloppy programmer and need to fix that.


ocean
Enter(atom/movable/O) // The default argument
if(istype(O, /mob/player)) //check to see if O is a player mob
var/mob/player/P = O //create a reference to a player mob, and assign O to it
if(!P.onboat) //If P is not on a boat
return 0 //Deny it entry
return ..() //Allow the default process to happen, in case some other code would deny access somewhere else in your code



This still isn't done, as /mob/giraffe and /obj/bannana could still wander freely amongst the waves, which may not be what you want :) It might be easier to create a new var, atom/movable/var/may_enter_water = FALSE, then set that to be true for anything you want to be able to enter the water (waves, /mob/players on a boat, fish, etc.) The proc is then a much smaller:

ocean
Enter(atom/movable/O)
if(!O.may_enter_water)
return 0
return ..()


In response to Flick
Or, you can save a few lines of code and just give waves the var onboat =)
In response to Spuzzum
Yeah, I found that out when I did a test....