When using the "Create Object" script, how do you change attributes of the created objects?

I wanted to make a key that could only be used once before it broke. Is there anyway to do that?


How I did this was I put all the properties I wanted on an existing object, duplicated that object and put it in the inventory of the player. I'm not that advanced, so that's how I avoid using the Create Object script to essentially do the same thing as you.

As an example, in my game, they are "quarters" that have a single use in an arcade machine. I have a coin conversion booth. The player pays a dollar, I decrease their money by that amount, then duplicate the "quarter" object that is hidden in the coin conversion booth's inventory and move the duplicate into the player's inventory. Perhaps there's a more advanced way that more experienced users can give you, but this could be a start!


Thank you, I'll try it out!


here's some examples of various things you can do:

(it can be made more robust of course, but this is just an example)

msg ("Input: NAME_OF_OBJECT_SEMICOLON_NAME_OF_ATTRIBUTE_SEMICOLON_NAME_OF_TYPE_OF_ATTRIBUTE_SEMICOLON_VALUE")
get input {
  stringlist_variable = Split (result, ";")
  name_of_object_string_variable = StringListItem (stringlist_variable, 0)
  name_of_type_of_attribute_string_variable = StringListItem (stringlist_variable, 1)
  name_of_attribute_string_variable = StringListItem (stringlist_variable, 2)
  value_variable = StringListItem (stringlist_variable, 3)
  object_variable = Create (name_of_object_string_variable)
  set (object_variable.name, "type_string_attribute", name_of_object_string_variable)
  if (name_of_type_of_attribute_string_variable = "integer") {
    value_variable = ToInt (value_variable)
  }
  on ready {
    set (object_variable.name, name_of_attribute_string_variable, value_variable)
  }
}

// -----------------

// input example: key;quantity;integer;1

// creates these Attributes:
//
// key.type_string_attribute = "key"
// key.quantity = 1

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums