Python References, want to get what SOL points to

This forum is currently in read-only mode.
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • I was wondering if anyone could help, I have condensed my problem down into like just the smallest reproduction of the issue, if this works it will be so epic i will finally never loose those blasted sprites.

    System.Create(Sprite, 2, xLocation, yLocation) #so we create a first sprite

    RefToFirstSprite = SOL.Sprite #we want to save some ref to it, this however saves a link to Sol.Sprite not the target of it which i want

    System.Create(Sprite, 2, xLocation, yLocation) #in creating this next sprite whatever sol points to somehow is updated

    RefToFirstSprite.Destroy() #and this ends up therefore killing the new target of sol, not the first sprite i wanted to get rid of

    I have racked my brains on this for seems like hours now, I feel at least satisfied I think I have identified my problem quite well, would be really greatfull if anyone could shed any light on what's happening here... i sort of have this impression I'm missing something fundamental

  • #This is how you save a object refrence

    System.Create("Sprite", 1, 200,200)

    RefToFirstSprite = SOL.Sprite[0]

    #Then you can destroy it later like so.

    RefToFirstSprite.Destroy()

  • wow, seriously thanks, i was really loosing it on that one. This is epic, no sprite will now be lost I was really being held back by that contemplating crazy workarounds

    that was clearly a rather fundamental python concept I wasn't getting i can't thank you enough

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • i wanted to share the code that has evolved from your advice:

    #####

    def Spawn(sSpawntype, x, y, iSpawnLayer):

         System.Create(sSpawntype, iSpawnLayer, x , y )

         cCodeToExec = "ref = SOL." + sSpawntype + "[0]"

         exec cCodeToExec

         return ref

    ####

    Then if you want to spawn something and never loose it:

    EvilBadGuy1 = Spawn(sSpawntype, x, y, iSpawnLayer)

    ####

    Thanks so much the possibilities are endless with this i can stream the tiles in and out as you walk about etc, awesome.

    When I found Python could build and run strings well I just knew I would be I was in love with this xD

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