On Tue, 5 Nov 2002, Bill Pascoe wrote: > I implemented the ferry code on the FTP website it works great > (after I fixed the send to room error). But > was I happy NO.... I decided it needed more. I wanted it so that when > <---snip--> > I think you should be able to get the picture. Now what in the world > is wrong with this. > <---snip--> Well, this: > struct obj_data *tobj; The pointer, tobj, gets reset every time the function is called since it's a local variable. You can solve this by making the variable "static". static struct obj_data *tobj; This comes with the disadvantage that you can only use the ferry routine for one ferry. With multiple ferries, every time a new object was creted, it would overwrite the old value of tobj. And if we assume the object can't be moved, there's still the problem that the object may get purged before the ferry routine is run. In that case, tobj points to memory which may longer be valid. That is, you may get random crashes from that code. If you really wanted to go so far, you could add another member to obj_data, a callback function pointer, called when the object is destroyed. Then, in your ferry routine, you would set up that callback pointer when you create the new object. Then, in extract_obj, call the callback function. That function, in turn, would have to update tobj to NULL (which means you'd have to make tobj global so callback function could access it). But that's overkill. DGScripts may allow you to do this in some fashion, but I've never used it. Hope this saves some headaches. -- +---------------------------------------------------------------+ | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html | | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html | | Newbie List: http://groups.yahoo.com/group/circle-newbies/ | +---------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 06/25/03 PDT