permanently deleting objects from the game.

Is there a way to do it so the save file won't eventually clog up with hundreds of extra objects or characters?
the game I have set up now creates objects by copying a single object with all the attributes an object of that type could possibly need and then assigning attributes based on name
for ex, if I want an Iron dagger, i can go genweapongen(iron,dagger) which copies a generic weapon, determines that it is a dagger, asssigns stats based on that and adds more to it based on it being iron or whatever other material if it's defined. the fun part is you could litterally put anything as the first word and you'll get it but the stats will be crap if it's not a particular material.
there is a similiar process for items and others. items is just itemgen(whatever the item is)
and enemies is enemgen(whatever the enemy is)
anyway, so if I sell the iron dagger at the shop, how would I delete it from the game as it isn't needed anymore?


I believe it's the "Destroy" function that completely deletes an object:

https://docs.textadventures.co.uk/quest/scripts/destroy.html

P.S. Your system sounds pretty cool.


If do that though I get "Error running script: Error compiling expression 'selitm': RootExpressionElement: Cannot convert type 'Element' to expression result of 'String'"


If do that though I get "Error running script: Error compiling expression 'selitm': RootExpressionElement: Cannot convert type 'Element' to expression result of 'String'"

The parameter to destroy is the name of the object, not the object itself; because variables pointing to the object become invalid when it is deleted. So you would have something like:

destroy ("stick95")

or in a command:

destroy (object.name)

However, beware of using this with commands that can handle multiple objects; or in places like an object's drop script.
Because a line like:

foreach (obj, some_objectlist) {

will crash the game if an object in some_objectlist is destroyed before the loop ends. This is why you can't destroy an object from its drop script – because things like "drop all" work, which means that the drop command uses foreach to process a list of objects, even though there's usually only one object in the list.

So if you want to destroy objects in a situation like this, you would make a turnscript (let's call it destruction) with a script like:

if (HasAttribute (game, "to_destroy")) {
  foreach (objectname, game.to_destroy) {
    destroy (objectname)
  }
}
this.enabled = false

and when you want to destroy an object, you would do:

if (not HasAttribute (game, "to_destroy")) {
  game.to_destroy = NewStringList()
}
list add (game.to_destroy, someobject.name)

Hope that all makes sense :D


I think I understand most of it. But I got a little lost because the solution to crashing the game by destroying objects in a list was to create lists to destroy objects from.

Does it mean that it will crash if the object being destroyed is in a list with objects that aren't being destroyed? So you have to make a special "destroy" list?


I think I understand most of it. But I got a little lost because the solution to crashing the game by destroying objects in a list was to create lists to destroy objects from.

When an object is destroyed, all variables pointing to it become empty, and it's removed from all lists that contain it. This is a problem with foreach, which requires the list not to change while it's running.

If you look, you'll see that the to_destroy list is a stringlist, containing the names of the objects to destroy. Unlike an objectlist, which can only contain existing objects, a stringlist is allowed to contain strings which are no longer equal to an object's name.


Log in to post a reply.

Support

Forums