Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Variable name — Gideros Forum

Variable name

NinjadoodleNinjadoodle Member
edited October 2015 in General questions
Hi guys

I'm trying to do something like this
self.lightSwitch1 = LightSwitch.new(pack1, 0, 0, items)
 
	local function switchTouch(target, event)
 
		if target:hitTestPoint(event.x, event.y) then
 
			if (target == lightSwitch1) then
				print('yo')
			end
is there a way to do this without setting a name property? (eg. lightSwitch1.name = lightSwitch1)

Thank you in advance!

Comments

  • As I was posting the above, I figure it out :)

    I was missing self. before lightSwitch1
  • john26john26 Maintainer
    edited October 2015 Accepted Answer
    Yes, if target and self.lightSwitch1 are both tables then "target == lightSwitch1" is comparing the memory addresses of the two tables. If they are the same then it must be the same table (not just two different tables with identical contents, the test for equality does not compare contents). So this method works well. You could also add a .name field (a string) and compare that.
    self.lightSwitch1 = LightSwitch.new(pack1, 0, 0, items)
    self.lightSwitch1.name="lightSwitch1"
     
    local function switchTouch(target, event)
     
      if target:hitTestPoint(event.x, event.y) then
     
          if (target.name == "lightSwitch1") then
               print('yo')
          end
      end
    end
    but I think your way is better and simpler.
Sign In or Register to comment.