setting sprite properties by name

0 favourites
  • 4 posts
From the Asset Store
Creepy Sprite Font suitable font for your Dark/Horror/Halloween games.
  • Hello,

    I'd like to set a sprite property by name. Is there an easy way to do this without resorting to javascript?

    E.g.

    Suppose I have a two text input fields where i can write into the name of a property, including instance variable names, and the value and upon pressing some button an action retrieves the name of the property from the field and sets its value.

    Can this easily be done?

    thank you,

    Dan

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I've never had to do this before, so I doubt this is the best way...but I used the Textinput to a dictionary, locating a sprite by name via Family then updating all the sprite's vars from the dictionary. Essentially you could match up dictionaries to sprites via UID/Var so they're paired up.

    dropbox.com/s/8ie9uljayyran1h/input_toSprite.c3p

  • Thank you for giving this a try.

    I am seeking a more general solution.

    Your code sets, for example, the sprite instance variable by referring to the instance variable name "red" -- which is selected from the dropdown list.

    I seek to use the key in the dictionary as the name of the property to set, so something like this

    Function createObjectFlexibtly(Object_Type_Name, aDictionary)

    Current_Object = System.Create ObjectByName(Object_Type_Name)

    for each aKey in aDictionary

    set Current_Object.aKey = aDictionary.current_value

    In the pseudo code above, the name of the object property is the key in the dictionary -- and the name of the object created is a parameter: Object_Type_Name of a function call.

    This makes this code very general -- and I don't have to write code for each object type that can be created and set.

    Clearly, whoever calls this will know what properties and instance variables the named object (in Param1) has, so that the code doens't try to set something that doesn't exist.

    Although, in javascript -- setting an object property that doesn't exist might actually create it -- although, this might not be aligned with how C3 manages instance variables of sprites.

    i hope i explained that understandably,

    Dan

  • I am now wondering if this can be achieved by adding a one line script that calls a function that uses the scripting interface to set the object properties and object instances.

    If this is the way to go, would be great if someone could show an examples how this could be done.

    Edit:

    I think i am getting closer :-)

    construct.net/en/make-games/manuals/construct-3/scripting/scripting-reference/iruntime

    runtime.objects.Sprite

    although I need to do this in a parameterized way -- somehow.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)