Thread Tools Display Modes
12-05-14, 06:06 AM   #1
analytical
A Defias Bandit
Join Date: Nov 2014
Posts: 3
Lua launguage

I am having problem with one of my function. This function (addShip) need to decide randomly whether it will be horizontal or vertical rectangles. I am trying to change some rectangles from (ship) attribute to true in a line in order to add a rectangle. For example, if I try to call a ship 2 it will be 2 rectangles in a row or column with a rectangle attribute value of true.



local gridWidth = 9
local gridHeight = 14
local grid = {}


for i = 1, gridWidth do
grid[i] = {}
end

Touch function
local function tappedRect(event)
if event.target.ship then
event.target.ship = true
event.target:setFillColor(255,0,0)
else
event.target.ship = false
event.target:setFillColor(0,255,0)
end
end



local squareWidth = 25
local squareHeight = 25
local gap = 5


for i = 1, gridWidth do
for j = 1, gridHeight do


local xPos = (gap*i) + (i*squareWidth)
local yPos = (gap*j) + (j*squareHeight)
grid[i][j] = display.newRect(xPos, yPos, squareWidth, squareHeight)
grid[i][j]:addEventListener("tap", tappedRect)

end
end

--Corona runtime ERROR (Main Lua ‘then expected near grid’)
--Add a ship
local function addShip( shipSize )
-- Set a random square location
local xPos = math.random(1, gridWidth)
local yPos = math.random(1, gridHeight)

for i = 1, shipSize-1, 1 do
if grid[x-i][y].ship then
if grid[x-i][y].ship == false
grid[x-i][y]:setFillColor(255,0,0)


end
end
end



addShip(2)

If anyone has any idea please let me know

Thank you all...
 
12-05-14, 06:24 AM   #2
Talyrius
An Onyxian Warder
 
Talyrius's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 363
What was wrong with your last thread?
 
12-05-14, 01:11 PM   #3
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Originally Posted by Talyrius View Post
What was wrong with your last thread?
You mean the one that Cairenn closed since it isn't relevant to the site's topic?
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
 
12-06-14, 04:20 AM   #4
Cairenn
Credendo Vides
 
Cairenn's Avatar
Premium Member
WoWInterface Admin
Join Date: Mar 2004
Posts: 7,134
What Torhal said.

Closing this one as well. If yet another gets posted, the OP will be banned.
 

WoWInterface » Developer Discussions » Lua/XML Help » Lua launguage


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off