2 Replies Latest reply on Apr 29, 2009 4:08 AM by Heffman

    Object Expected error upon opening file.

    Heffman

      Hey folks, I'm having a problem with a list I've created for an RPG I'm working on as a uni project, the list is this...

       

      on beginsprite me

           aPlayerType = [#HP:2, #Def:1, #Dam:1, Spd:1, #Blk:0]
           iStartStat = 5

           aPlayerStats = [#Strength:iStartStat, #Toughness:iStartStat, #Stamina:iStartStat, #Agility:iStartStat, #MaxHealth:(iStartStat*(aPlayerType[#HP])),     #CurHealth:(aPlayerStats[#MaxHealth]), #PlayerLevel:1, #Damage:(iStartStat*(aPlayerType[#Dam])), #Defence:(iStartStat*(aPlayerType[#Def])),     #Speed:(iStartStat*(aPlayerType[#Spd])), #Block:(aPlayerType[#Blk]), #Experience:0]

      end

       

       

      My problem with it is that upon opening my director file to work on/test etc, it gives me the script error: object expected on the line defining aPlayerStats whenever I start the movie.

       

      I can resolve the issue by breaking my list and making it smaller, what I do is keep aPlayerStats = [#Strength:iStartStat] and comment out the rest. I can then compile the code, start and stop the movie and everything is fine. Once this is done, I can restore the list to it's original form and everything works as expected

       

      Is there some issue I've missed that is causing it to error when newly opened? I can't figure out why it would work like this.        

        • 1. Re: Object Expected error upon opening file.
          Sean_Wilson Adobe Community Professional

          Your problem is the property value you're trying to define at

          #CurHealth:(aPlayerStats[#MaxHealth])
          

          You can't initialise a list and reference one of its values all in the same line of code. When trying to create the value associated with #CurHealth you are trying to reference a property of an as-yet non-existant list.

          Break it up into 2 steps:

          on init
            aPlayerType = [#HP:2, #Def:1, #Dam:1, Spd:1, #Blk:0]
            iStartStat = 5
            
            aPlayerStats = [#Strength:iStartStat, #Toughness:iStartStat, #Stamina:iStartStat, #Agility:iStartStat, #MaxHealth:(iStartStat*(aPlayerType[#HP])), #PlayerLevel:1, #Damage:(iStartStat*(aPlayerType[#Dam])), #Defence:(iStartStat*(aPlayerType[#Def])), #Speed:(iStartStat*(aPlayerType[#Spd])), #Block:(aPlayerType[#Blk]), #Experience:0]
            aPlayerStats[#CurHealth] = aPlayerStats[#MaxHealth]
          end
          
          • 2. Re: Object Expected error upon opening file.
            Heffman Level 1

            Thanks for the assist, that's spot on.

             

            Much appreciated!

             

            I'd swapped all of the values for actual numbers, instead of referencing the list and the iStartStat value, and noticed that it worked fine, but your fix is better as it keeps everything much tidier and accessible.