ID:149518
 
Hello everyone. Here is a tip. If you have a problem as in you don't know how to do something for your game, see if you can set a variable to help it. E.G: I have a note that you cant read cause the writing is too small, so you need a magnifying glass. I think you can set some code for it but I dont know it. So I set a variable hasglass and when you pick up the hasglass = 1. So you make it for the read verb for your note say if usr.hasglass = 0 usr << "It is too small writing" etc. I hope this has helped you.

From Cjpe
That's good advice. A simple way to improve on it comes to mind, though, so I feel the need to share it with you. Having a variable for so many things gets cluttered, you see. Example:
mob/var
armour_equipped = 0
has_glass = 0
weapon_equipped = 0
superpowers_learned = 0
has_dungsack = 1

Though all of these vars probably have very legit uses, why not condense them down into an associative list?
mob/var/list/itemCheck = list()

Then, you don't even have to define the vars. You can do it like this:
scroll
var/contents = "<small>If you can read this, you either have way good eyes or you found the glass!</small>"
proc/Read()
if(usr.itemCheck["has_glass"] == 1)
usr << src.contents
else usr << "The writing is too small!"
glass
proc/Hold()
usr << "You hold the glass in your hand."
usr.itemCheck["rightHand_in-use"] = 1
usr.itemCheck["has_glass"] = 1

This makes a lot less work for you as you create more specialized items that require variable checks of this sort.

-Lord of Water
In response to Lord of Water
If you have a variable(or an associative list) for everytime you have something like that, you will quickly build up immense amounts of useless variables or a huge amount of lag when searching through a list. Lucky for us all, there is a great way to do something without all the variable mumbo-jumbo. locate(). (Look it up!)

If you want to do more than simply check for an item existance, you can even set up a system of 'item requirements', so you can check a variable(or list) to see if the person has the required items to use it. Mayby something like this?
atom/movable/CheckReq(O) // prototype proc for all movable atoms

atom/movable
var/list/requirements=list()
CheckReq(O)
var/req
if(requirements.len) // if there are requirements
for(var/a in requirements)
var/avalue // associative value. If it has an associative value, its a 'locate'
avalue = requirements["[a]"]
if(avalue && istype(avalue,/atom/movable/))
req = locate(avalue) in O
if(!req) return 0 // they don't have the required item!
continue // next!
else if(!avalue)
if(O.vars[a] < requirements[a]) return 0 // they don't meet the variable requirement
continue
return 0 // they must have specified a faulty avalue, so just quit the proc.
Then you could do something like this:
obj/verb/Equip()
if(!CheckReq(usr)) return 0
// ...other code here


Of course this is all hypothetical code, and it won't even compile if you were to copy-paste it and properly indent. And I guess I strayed a bit off-point, but the point was :

There are much better ways of doing things like this. Having huge lists of item variables would become tedious very fast, and very slow.

As a side note, setting things like equipment variables to boolean values is a bad idea. What if you have to find the item you are wearing in your right hand? Instead of simply extracting it from a variable, you'd have to loop through items and check their variables.

Alathon