[SOLVED] Assign text to an instance (SOL Python)

This forum is currently in read-only mode.
  • Hi!

    Right now I'm working on some dynamic menus for a miniRPG project. I wanted to create a menu with Python by using a function with a parameters, like this:

    display("Title","Content",["OK,"CANCEL"])

    and then

    def display(title,content,options):
        ...
        # CREATION OF NEW OBJECTS
              for items in options:
                  ?System.CreateByName("POPUP_OPTION_BG","POPUP",Window.Width-128-option_offset,POPUP_TITLE_BG.Y+POPUP_BG.Height+32)
                  ?System.CreateByName("txt_option","POPUP",Window.Width-128-option_offset,POPUP_TITLE_BG.Y+POPUP_BG.Height+32)
                  ?#System.Create("txt_option","POPUP",Window.Width-128-option_offset,POPUP_TITLE_BG.Y+POPUP_BG.Height+32)
                  ?option_offset += 144

    The trouble starts when I try to assign Text values to those objects. I want to iterate through them and set every each instance with it's own option text. I've tried setting the text on creation and this method (found on SourceForge net page), just to set every instance with this text, for debug reasons:

    for t in txt_option:
         t.Text= "something"

    but it didn't work as expected. This sets the new text for only one instance, the one existing in the layout before the creation. Is there a way to do this at all? I really would prefer dynamic creation of objects rather than hiding / showing trick for objects already on the layout...

    Any help appreciated!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can access the last created instance with:

    SOL.txt_option[0]

    But this won't help if you create multiple instances at once.

    You could make a function like this to return a reference to a newly created object, then you could store the references in a list or something.

    def my_create(name, layer, x, y):
        System.Create(name,layer,x,y)
        return eval("SOL."+name+"[0]")
  • Well, this seems to be what I'm looking for, thank you! I'm creating instances in a loop, one per loop, so accessing that instance in that loop should do just fine, I suppose. Also, storing a dictionary or a list of SOL items created that way in a Hash Table sounds very promising! Great idea.

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