ID:150279
 
Ok I've started trying to refrain from posting her too often, but this little problem just keeps growing in errors. I went from 19 to now 30 errors. What I'm trying to do is set a var "pwater" (plant's water level). Depending on what the water level is will determine the icon state.
Also if the pwater level is 4 then it will also allow anyone with a farm var of 5 or more to see the verb to harvest.

// Object States
obj
var
pwater = 0

// Fields
obj
field
name = "Field"
icon = 'field.dmi'
switch(pwater)
if(pwater == 0) icon_state="empty"
if(pwater == 1) icon_state="grow1"
if(pwater==2) icon_state="grow2"
if(pwater==3) icon_state="grow3"
if(pwater==4) icon_state="grow4"
if(usr.farm > 5)
verb/Harvest()
usr << "You have harvested the field."
pwater=0

Any ideas?
LJR
Well, to start with when you use a switch, it goes like this:

switch(variable_in_use)
//So you don't need to follow it with if(variable == this),
//just do this:
if(1)
if(2)
//since it's already knows what variable you're using.

Also, you've got the if(usr.farm > 5) command on the wrong line, it should be two tabs back.

And the verb is totally in the wrong spot, you cannot declare a verb in the middle of an operation, that makes no sense. A verb needs to be declared right after the object itself is declared, so:

obj/whatever/verb/YourVerb()

That's all I see for now.



// Object States
obj
var
pwater = 0

// Fields
obj
field
name = "Field"
icon = 'field.dmi'
switch(pwater)
if(pwater == 0) icon_state="empty"
if(pwater == 1) icon_state="grow1"
if(pwater==2) icon_state="grow2"
if(pwater==3) icon_state="grow3"
if(pwater==4) icon_state="grow4"
if(usr.farm > 5)
verb/Harvest()
usr << "You have harvested the field."
pwater=0

Any ideas?
LJR
Aside from what Gate pointed out below, there is an easier way to set an icon state based on some variable of an object. For example, you could name your icon states "0," "1," "2," "3," and "4." Then you could have code like this:
obj/field
icon = 'field.dmi'
var pwater=0

proc
show_water()
icon_state="[pwater]"

New()
show_water()


Later, if pwater changes, just make sure to call show_water(). Also make sure you have an icon state for each possible value of pwater.
Well for the verb I'm /* */ it out till I can get the icon states working. I corrected my switch statement, still the compiler doesn't like. I get the following errors

switch(pwater)
error:pwater:value not allowed here

if(0) icon_state="empty"
error:0:duplicate definition

This error continues on for 1,2,3,4 as well.

So my new code looks like the following:
---------------------------------------------
// Fields
obj/field
var pwater = 0
name = "Field"
icon = 'field.dmi'
switch(pwater)
if(0) icon_state="empty"
if(1) icon_state="grow1"
if(2) icon_state="grow2"
if(3) icon_state="grow3"
if(4) icon_state="grow4"
obj
var
pwater = 0


This is a joke, right? You're just trying to tempt us. Come on... as if pee bags weren't enough, you just had to make pee water?

-AbyssDragon
In response to AbyssDragon
I knew someone was going to bring that up.
In response to AbyssDragon
AbyssDragon wrote:
obj
var
pwater = 0


This is a joke, right? You're just trying to tempt us. Come on... as if pee bags weren't enough, you just had to make pee water?

-AbyssDragon

Have, what ever does the trick! ;-P
In response to GateGuardian
I couldn't resist. My will is just not that strong.

-AbyssDragon
In response to LordJR
LordJR wrote:
So my new code looks like the following:
---------------------------------------------
// Fields
obj/field
var pwater = 0
name = "Field"
icon = 'field.dmi'
switch(pwater)
if(0) icon_state="empty"
if(1) icon_state="grow1"
if(2) icon_state="grow2"
if(3) icon_state="grow3"
if(4) icon_state="grow4"

Maybe I'm wrong, but I don't think you can have a switch statement outside of a proc or verb like that. You would need to have that within New(), or within its own proc, which gets called from New(). Than call it again whenever peewater changes.

obj/field/proc/Current_State()
switch(pwater)
if(0) icon_state="empty"
if(1) icon_state="grow1"
if(2) icon_state="grow2"
if(3) icon_state="grow3"
if(4) icon_state="grow4"
obj/field/New()
..()
Current_State()

Than, whenever you change peewater, call Current_State()


As far as having the verb only show up for people who are high enough level, I don't think you can do that (at least, not easily... I suppose you could have fields add the verb to all appropriate mobs which come within a certain distance). It would be much simpler to allow anyone to try, but only allow those of high enough level to succeed.

flick()