ID:166842
 
Sorry everyone, How do I use IFs and areas?
if my map has for example 3 areas, hospital, police and streets, how do I use ifs to have different results to a verb depending on the place I am in?
a bit like the following:
IF area_im_in=area/hospital
THEN do this with the verb 'work'
IF area_im_in=area/police
THEN do this other thing with the verb 'work'
ELSE do that with the verb 'work'


I've already learnt loads, but is beginning to get complicated for a rookie like me!
if(something)
do this
else
do this


example:

if(usr.dead==1)
usr<<"You dead!"
del(usr)
else
usr<<"You alive"
In response to Ripiz
Iv've got this far on my own
area/street
Enter()
usr <<"youre at a pitch"
return..()

area/police
Enter()
usr <<"no busking here"
return..()

area/hospital
Enter()
usr <<"silence"
return..()

area/bank
Enter()
usr <<"this is the bank"
return..()

but each time I put a verb or proc inside it doesnt work,
how can I use the following code only when the player is in the street?
mob/verb/pass_hat(mob/M in oview(2))
if(M.class == "joe_public")
var/amount = (rand(1,M.gold)/100)
M.gold -= amount
usr.gold += amount
world << "[usr] hats [M] , getting [amount] Euros!"

else world << "[usr] passes hat for nothing!"

and not in the other places

In response to Ripiz
where's the problem?
mob/verb/pass_hat(mob/M in oview(2))
var/pos = usr.loc
if(M.class == ("joe_public") && (!istype(pos,/area/pitch))
var/amount = (rand(1,M.gold)/100)//line 8
M.gold -= amount
usr.gold += amount
world << "[usr] hats [M] , getting [amount] Euros!"
else world << "[usr] passes hat for nothing!"

musicwave.dm:8:error: var: missing comma ',' or right-paren ')'
In response to Eurobusker
Eurobusker wrote:
where's the problem?
mob/verb/pass_hat(mob/M in oview(2))
if(M.class == "joe_public" && istype(loc.loc,/area/pitch))
var/amount = (rand(1,M.gold)/100)
M.gold -= amount
usr.gold += amount
world << "[usr] hats [M] , getting [amount] Euros!"
else world << "[usr] passes hat for nothing!"


Your location is a turf, and a turf's location is an area, so loc.loc is your area :)

Also, that error is because your one parenthesis short on the if() above that line.

Oh, and you should use more than one space for indenting... I suggest tabs :)
In response to DarkCampainger
this is better?
mob/verb/pass_hat(mob/M in oview(2))

var/pos = usr.loc
if(M.class == ("joe_public") && (!istype(pos,/area/pitch)))
var/amount = (rand(1,M.gold)/100)
M.gold -= amount
usr.gold += amount
world << "[usr] hats [M] , getting [amount] Euros!"
else world << "[usr] passes hat for nothing!"
<dm>

it does not give errors, but I thought the verb would only work when I was on the area/pitch.
It in fact works everywhere lol!!
why is this?
In response to Eurobusker
Look at the code I posted. You'll notice a few key changes from yours.

The first change was switching "(!istype(pos,/area/pitch))" with "istype(loc.loc,/area/pitch)". The ! opperator can somewhat literally be translated to "not". So "!istype(pos,/area/pitch)" would only be true if they weren't in the pitch area, which I assume isn't what you want.

Also, "pos" was removed completely and replaced with "loc.loc". I explained this in my previous post.

I see you started using tabs, good to see :)
In response to DarkCampainger
Sir DarkCampainger, you are GOD!!!
thanks, now I got it!
In response to Eurobusker
mob/var
street
area/street
Enter()
usr <<"youre at a pitch"
street=1
return..()
Exit()
street=0

area/police
Enter()
usr <<"no busking here"
return..()

area/hospital
Enter()
usr <<"silence"
return..()

area/bank
Enter()
usr <<"this is the bank"
return..()


mob/verb/pass_hat(mob/M in oview(2))
if(usr.street==0)
usr<<"You can use it only in street!"
else
if(M.class == "joe_public")
var/amount = (rand(1,M.gold)/100)
M.gold -= amount
usr.gold += amount
world << "[usr] hats [M] , getting [amount] Euros!"

else world << "[usr] passes hat for nothing!"
In response to Ripiz
[b]Oh my God[/b]

Ripiz, seriously. Your intentions might be good, but that's plainly horrible.

1. If you look up Enter()/Entered()/Exit()/Exited() in the reference, you'd see they pass arguments. <code>usr</code>? Hell no. Hell hell hell no.

2. Your way of setting a var when entered the street is wrong, first there is <code>usr</code>, as said above, secondly you're using Boolean vars.
For TRUE/FALSE values

if(var==1) //WRONG
if(var) // JEZUS LOVES YOU

if(var==0) //WOULDN'T BET ON IT
if(!var) // HAVE MY NOODLES! :D


The <code>!</code> operator is lovely, lovely, lovely. Mind you, I prefer the <code>?</code> operator. That one is off-topic, I plainly wub it.

3. Even with the boolean vars fixed, it's still positively wrong. What if the mob was teleported, warped, or whatever? Lots of bug abusing/glitching that way. See this;
if(istype(usr.loc.loc,/area/street))


It'll check the <code>usr</code> is standing on that particular area. You think istype() could only be used on mobs? Experiment!
Ow, and about that <code>usr.loc.loc</code>, it's easy to explain.
<code>usr.loc</code> will output a turf
<code>usr.loc.loc</code> That is the turf's loc. Which will be an area.
In response to Mysame
thank-you all, I've got this, which is a mixture of all the propositions. AND IT WORKS!!!
area/pitch
Enter()
usr <<"youre at a pitch"
return..()

area/police
Enter()
usr <<"police station"
return..()

area/hospital
Enter()
usr <<"hospital"
return..()

area/bank
Enter()
usr <<"bank"
return..()

mob/verb/pass_hat(mob/M in oview(2))
if(M.class == "joe_public" && istype(loc.loc,/area/pitch))
var/amount = (rand(1,(M.gold/2))-1)
M.gold -= amount
usr.gold += amount
world << "[usr] hats [M] , getting [amount] Euros!"
return..()

if(istype(loc.loc,/area/police))
usr << "[M] calls the police!"
world << "[usr] is wanted by the police for hatting in a police station"
wanted = "YES"
return..()

if(M.class == "joe_public" && istype(loc.loc,/area/hospital))
var/amount = (rand(1,M.gold)/10)
M.gold -= amount
usr.gold += amount
world << "[usr] hats [M] , getting [amount] Euros! at the hospital"

if(M.class == "joe_public" && istype(loc.loc,/area/bank))
var/amount = (rand(1,M.gold)/10)
M.gold -= amount
usr.gold += amount
usr << "[usr] hats [M] , getting [amount] Euros! at the bank"
world << "[usr] is hatting in the Bank"
return..()
else world << "[usr] busks for nothing!"

I'm learning fast,its like learning flamenco guitar, the more you learn, the more there is to learn. thanks all.
half time score germany 2 costa rica 1
In response to Eurobusker
Eurobusker wrote:
its like learning flamenco guitar, the more you learn, the more there is to learn.

Ha! What an analogy. I'll use that one some time -- what's programming like? It's like flamenco guitar. Genius.
In response to PirateHead
Eurobusker, did you even READ my posts? Imagine, please, that an obj would enter. What'd happen? Runtime the host, return 0, repeat. Game would eventually crash.

Because I'm feeling sort of shizzly atm, I'll type something up.
Enter(var/atom/movable/a)
if(ismob(a)) // If a is a mob
var/mob/M=a // Make 'a' a mob, so we can acces the vars
...
In response to Mysame
Mysame wrote:
> Enter(var/atom/movable/a)
> if(ismob(a)) // If a is a mob
> var/mob/M=a // Make 'a' a mob, so we can acces the vars
> ...
>


You don't even really need to do that. This works just fine:

whatever/Enter(mob/M)
if(istype(M)) //do_whatever
..()
In response to PirateHead
Yes, but if you want it to do something different also, for instance with an obj, that wouldn't work. Though, I never trted setting the M to an obj. Meh, doubt it'll work.