|
help > w > guide new wizard
A guide for new wizards, in no particular order.
Presumably, this could better be labelled as tips and tricks.
1. Strong type everything you code - it will save time later.
2. Note that storing objects in arrays (e.g. this_player(), etc) will
not work when the object disappears (e.g. the player logs out). Better
to store a string (e.g. this_player()->query_real_name()).
3. You may have seen locker_init locker_arg functions on objects
that save a particular configuration. This is outdated and replaced
by add_configuration in std/object/config.c
Here is how it works. Suppose a particular variable on an object is
changed (e.g. quest items which are bound to a player), or the number
of uses remaining for an orb. Let's take the orb for example.
In the old code, you would have to set
locker_arg() { return healing; }
locker_init(arg) { healing = to_int(arg); }
because healing is a variable that has to be stored across reboots, etc.
Simply create a function in the orb
void set_healing(int x){
healing = x;
}
and then each time the value of healing is changed when the orb
is used, put a:
remove_configuration("set_healing"); // remove old var
add_configuration("set_healing", x); // add new var
so the question now is: locker_arg() and locker_init(arg) looks
easier than creating a setter function, as well as having
remove_configuration / add_configuration in the code. Why should
we do this?
The main issue is when we have many more variables to store
and locker_arg / locker_init(arg) functions can get trickier.
4. inherit where possible
5. Best to store data as mappings (or mappings of mappings),
rather than have many different variables / storing them
in an array. For example, the mapping lots has
"d/gladstadt/ariston/room/roads/lot":({"fosters","This is Fosters's lot.",
"pub","Fosters'spub",1582419152,0,57,0,})
as one of its keys. The value of the key is slightly incomprehensible.
On the other hand,
"d/gladstadt/ariston/room/roads/lot":([ "owner_name":"fosters",
"short_desc":"This is Foster's lot.", "shop_type":"pub",
"long_desc":"Fosters'spub", "last_visit":1582419152,
"non_humanoid":0, "owner_id":57])
makes more sense. Moreover, in the first example, the array only has
8 elements, and 7 are used. If we want to add more info as time
goes by, deleting and constructing a new array is tricky (see locker
allocation bug which caused lockers to bloat). But we can easily add
new elements to a mapping, in this case:
lots["d/gladstadt/ariston/room/roads/lot"] =
lots["d/gladstadt/ariston/room/roads/lot"] += (["new_key":"new_val"]);
6. See more more /obj/shared/managed_bonuses.c for adding skill bonuses, and
/d/rymalind/fdcastle/obj/luckycharm.c for an example.
|