Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Error
Started by ConveyedRex7592 Dec 06 2019 03:41 AM

7 replies to this topic
error

Best Answer schizoid2k , 06 December 2019 - 06:34 AM

It's probably not enough code to give a definitive answer, but you are declaring "local hero" too many times.  Depending on where/when this is executed, you can be referencing a nil object, or a locally declared object.

 

Declare it 1 time and reuse.  If you need it in multiple functions, declare it outside of a function.

local hero = nil

local function Attack(event)
    hero = display.newSprite(AttackAnimationSheet, sequenceData)
    -- etc, etc
end

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

ConveyedRex7592

[GLOBAL: userInfoPane.html]
ConveyedRex7592
  • Observer

  • 27 posts
  • Corona SDK

I don't understand.... What's wrong?

Corona version: 2018.3326

Attached Files



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,177 posts
  • Corona SDK

You are trying to remove a display object that doesn't exist.

 

If you just share the error message, then that's really all the help you can get.


  • pixec likes this

[TOPIC: post.html]
#3

ConveyedRex7592

[GLOBAL: userInfoPane.html]
ConveyedRex7592
  • Observer

  • 27 posts
  • Corona SDK

But local variable "hero" exists...



[TOPIC: post.html]
#4

schizoid2k

[GLOBAL: userInfoPane.html]
schizoid2k
  • Contributor

  • 577 posts
  • Corona SDK

Probably a scoping issue.  As XeduR states, you need to post relevant code.



[TOPIC: post.html]
#5

AngelaMcCall

[GLOBAL: userInfoPane.html]
AngelaMcCall
  • Enthusiast

  • 52 posts
  • Corona SDK

If you were to give your hero object a string parameter name 
eg

hero.myName = "Superman"

You could then test if your hero object really does exist easily, directly before removing it.
EG

print("hero name: " .. hero.myName )
if the console reports a nil value and an error, then you will prove to yourself that the hero object doesn't exist which means you need to walk through your code to see where it becomes initiated... chances are it's not being created when you think it is.



[TOPIC: post.html]
#6

ConveyedRex7592

[GLOBAL: userInfoPane.html]
ConveyedRex7592
  • Observer

  • 27 posts
  • Corona SDK

But console reports hero name what I typed in....

Attached Files



[TOPIC: post.html]
#7

schizoid2k

[GLOBAL: userInfoPane.html]
schizoid2k
  • Contributor

  • 577 posts
  • Corona SDK

  Best Answer

It's probably not enough code to give a definitive answer, but you are declaring "local hero" too many times.  Depending on where/when this is executed, you can be referencing a nil object, or a locally declared object.

 

Declare it 1 time and reuse.  If you need it in multiple functions, declare it outside of a function.

local hero = nil

local function Attack(event)
    hero = display.newSprite(AttackAnimationSheet, sequenceData)
    -- etc, etc
end

  • pixec likes this

[TOPIC: post.html]
#8

pixec

[GLOBAL: userInfoPane.html]
pixec
  • Contributor

  • 173 posts
  • Corona SDK

Taking pictures of your code is a lot of work. Just use code inject tool


[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: error