Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

need help error attempt in table
Started by owlondrugs May 28 2018 11:37 AM

8 replies to this topic
table
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

owlondrugs

[GLOBAL: userInfoPane.html]
owlondrugs
  • Observer

  • 5 posts
  • Corona SDK

tilemap = {{1,1,1,1,1},
          {1,0,0,0,0},
          {1,1,1,1,1},
          {1,0,0,0,0},
}
for i=1,5 do
for j=1,4 do
if tilemap[i][j]== 1 or nil then
 
         local tile = display.newImageRect( tiles,1,32,32)
         tile.x = 32*i-32+128
         tile.y = 32*j-16+128
         return nil
end
end
end
 


[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,375 posts
  • Corona SDK

We need more details that this.  What is the exact error message and what line of code does it complain about exactly (mark it for us).

 

Also, FYI, you can and should format code posts for legibility.

 

formatyourcode.jpg



[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,375 posts
  • Corona SDK

tilemap = {{1,1,1,1,1},
          {1,0,0,0,0},
          {1,1,1,1,1},
          {1,0,0,0,0},
}
for i=1,5 do
   for j=1,4 do
      if tilemap[i][j]== 1 or nil then 
         local tile = display.newImageRect( tiles,1,32,32)
         tile.x = 32*i-32+128
         tile.y = 32*j-16+128
         return nil
      end
   end
end

I think you really mean this:

for i=1,4 do
   for j=1,5 do



[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,375 posts
  • Corona SDK

Oh, and as this is your first post.  Welcome to the community.  :)

 

But I have to say, I'm not happy because now my mind is wandering while I need to work, thinking about what an 'owl on drugs 'looks like.

 



[TOPIC: post.html]
#5

owlondrugs

[GLOBAL: userInfoPane.html]
owlondrugs
  • Observer

  • 5 posts
  • Corona SDK

Oh, and as this is your first post.  Welcome to the community.  :)

 

But I have to say, I'm not happy because now my mind is wandering while I need to work, thinking about what an 'owl on drugs 'looks like.

 

Ahahaahahahah



[TOPIC: post.html]
#6

owlondrugs

[GLOBAL: userInfoPane.html]
owlondrugs
  • Observer

  • 5 posts
  • Corona SDK

tilemap = {{1,1,1,1,1},
          {1,0,0,0,0},
          {1,1,1,1,1},
          {1,0,0,0,0},
}
for i=1,5 do
   for j=1,4 do
      if tilemap[i][j]== 1 or nil then 
         local tile = display.newImageRect( tiles,1,32,32)
         tile.x = 32*i-32+128
         tile.y = 32*j-16+128
         return nil
      end
   end
end

I think you really mean this:

for i=1,4 do
   for j=1,5 do

It's doesn't work...
Engine draw one box.



[TOPIC: post.html]
#7

owlondrugs

[GLOBAL: userInfoPane.html]
owlondrugs
  • Observer

  • 5 posts
  • Corona SDK

Ohhhh...I decided it problem.



[TOPIC: post.html]
#8

owlondrugs

[GLOBAL: userInfoPane.html]
owlondrugs
  • Observer

  • 5 posts
  • Corona SDK

Guys how to make the object move only when a key is pressed and not do movement when a key is not pressed?

I try to my with loop, the program crashes...

local mycircle = display.newCircle(32,display.contentHeight/2, 32 )
local function KeyEvent(event)

if event.keyName=="up" then
	mycircle.y=mycircle.y - 8
end
if  (event.keyName=="down") then
	mycircle.y=mycircle.y + 8
end
return false
end

Runtime:addEventListener( "key", KeyEvent )
print(mycircle.y)



[TOPIC: post.html]
#9

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,375 posts
  • Corona SDK

1.  This question doesn't seem related to the first.  Please always start a new thread when asking questions on new topics (and your game isn't a topic :) ).

 

2. Use an enterFrame listener to move the object.

local moveMagnitude = 8

local myCircle = display.newCircle(32,display.contentHeight/2, 32 )
myCircle.moveUp = 0

-- finalize listener to remove key and enterFrame listeners when object is deleted
function myCircle.finalize(self)
   Runtime:removeEventListener( "enterFrame", self )
   Runtime:removeEventListener( "key", self )
end
myCircle:addEventListener("finalize")

-- enterFrame - To move object
function myCircle.enterFrame( self )
   self.y = self.y + self.moveUp
   print( self.y )
end
Runtime:addEventListener( "enterFrame", myCircle )

-- Key listener to adjust how much circle should move frame to frame
function myCircle.key( self, event )
   local key = event.keyName
   local phase = event.phase

   -- UP ARROW KEY PRESS
   if( key = "up" and phase = "down" ) then
      self.moveUp = self.moveUp - moveMagnitude

   -- UP ARROW KEY RELEASE
   elseif( key = "up" and phase = "up" ) then
      self.moveUp = self.moveUp + moveMagnitude

   -- DOWN ARROW KEY PRESS
   if( key = "down" and phase = "down" ) then
      self.moveUp = self.moveUp + moveMagnitude

   -- DOWN ARROW KEY RELEASE
   elseif( key = "down" and phase = "up" ) then
      self.moveUp = self.moveUp - moveMagnitude
   end

   return false
end
Runtime:addEventListener( "key", myCircle )




[topic_controls]
[/topic_controls]