It has a property that tells us it can be carried, though the object is not yet held by anyone. G_nextObjectID = 1 - assigns ID 1 to the first objectĪbove, the function add_obj() is called with a few parameters that can be used for creating a simple box object. Object propertiesĪt this point I would like to store object properties in a global table, which we could call g_objData. With the object ID approach, moving objects from a room to the player inventory, or vice versa, is relatively simple and mainly involves moving the object IDs around, combined with changing a few properties. The double periods “.” concatenates the strings together as a single string. The string is comprised of “ID” + the number of zero’s + the short id number in string form. #num returns the length of the number string, similarly like writing string.len(num).įinally the function returns the ID. String.rep replicates the first argument “0” as many times as needed maxlength – #num. Local zeros = string.rep("0", maxlength - #num)Ībove, tostring(id_short) transforms the value of id_short into a string. function get_ID_format(id_short) - Returns a long ID object 1 = ‘ID000001’īelow is a simple function I wrote that transforms numbers into an ID code format like the above example. While you could compress the object IDs to hexadecimal format or using bits and bytes, I prefer having the IDs clearly readable for code debugging reasons. The benefit of this approach is that you don’t need to move around a lot of data when moving the objects in the game. Third part – Object IDs and object propertiesįor my interactive fiction game I want to access my objects via ID codes.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |