attempt to call global 'addButtons' (a nil value) - lua

I need help with a really annoying error I've been getting with my GMOD gamemode. I am trying to make a custom menu, but I get this error:
[ERROR] gamemodes/tdm/gamemode/custom_menu.lua:20: attempt to call global 'addButtons' (a nil value)
1. gameMenu - gamemodes/tdm/gamemode/custom_menu.lua:20
2. unknown - gamemodes/tdm/gamemode/custom_menu.lua:32
3. include - [C]:-1
4. unknown - gamemodes/tdm/gamemode/cl_init.lua:3
Here is my code:
custom_menu.lua
local Menu
function gameMenu()
if(Menu == nil) then
Menu = vgui.Create("DFrame")
Menu:SetSize(750, 500)
Menu:SetPos(ScrW() / 2 - 325, ScrH() / 2 - 250)
Menu:SetTitle("Gamemode Menu")
Menu:SetDraggable(true)
Menu:ShowCloseButton(false)
Menu:SetDeleteOnClose(false)
Menu.Paint = function()
surface.SetDrawColor(60, 60, 60, 255)
surface.DrawRect(0, 0, Menu:GetWide(), Menu:GetTall())
surface.SetDrawColor(40, 40, 40, 255)
surface.DrawRect(0, 24, Menu:GetWide(), 1)
end
addButtons(Menu)
gui.EnableScreenClicker(true)
else
if(Menu:IsVisible()) then
Menu:SetVisible(false)
gui.EnableScreenClicker(false)
else
Menu:SetVisible(true)
gui.EnableScreenClicker(true)
end
end
end
concommand.Add("open_game_menu", gameMenu())
function addButtons(Menu)
local playerButton = vgui.Create("DButton")
playerButton:SetParent(Menu)
playerButton:SetText("")
playerButton:SetSize(100, 50)
playerButton:SetPos(0, 25)
playerButton.Paint = function()
--Color of entire button
surface.SetDrawColor(50, 50, 50, 255)
surface.DrawRect(0, 0, playerButton:GetWide(), playerButton:GetTall())
--Draw Bottom and Right borders
surface.SetDrawColor(40, 40, 40, 255)
surface.DrawRect(0, 49, playerButton:GetWide(), 1)
surface.DrawRect(99, 0, 1, playerButton:GetTall())
--Draw Text
draw.DrawText("Player", "DermaDefaultBold", playerButton:GetWide() / 2, 17, Color(255, 255, 255, 255), 1)
end
playerButton.DoClick = function(playerButton)
local playerPanel = Menu:Add("PlayerPanel")
end
local shopButton = vgui.Create("DButton")
shopButton:SetParent(Menu)
shopButton:SetText("")
shopButton:SetSize(100, 50)
shopButton:SetPos(0, 75)
shopButton.Paint = function()
--Color of entire button
surface.SetDrawColor(50, 50, 50, 255)
surface.DrawRect(0, 0, shopButton:GetWide(), shopButton:GetTall())
--Draw Bottom and Right borders
surface.SetDrawColor(40, 40, 40, 255)
surface.DrawRect(0, 49, shopButton:GetWide(), 1)
surface.DrawRect(99, 0, 1, shopButton:GetTall())
--Draw Text
draw.DrawText("Shop", "DermaDefaultBold", shopButton:GetWide() / 2, 17, Color(255, 255, 255, 255), 1)
end
shopButton.DoClick = function(shopButton)
local shopPanel = Menu:Add("ShopPanel")
end
end
--Player Panel
PANEL = {} -- Create an empty panel
function PANEL:Init() --Initialize the panel
self:SetSize(650, 475)
self:SetPos(100, 25)
end
function PANEL:Paint(w, h)
draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 255))
end
vgui.Register("PlayerPanel", PANEL, "Panel")
--End Player Panel
--Shop Panel
PANEL = {} -- Create an empty panel
function PANEL:Init() --Initialize the panel
self:SetSize(650, 475)
self:SetPos(100, 25)
end
function PANEL:Paint(w, h)
draw.RoundedBox(0, 0, 0, w, h, Color(255, 255, 255, 255))
end
vgui.Register("ShopPanel", PANEL, "Panel")
--End Shop Panel
init.lua:
AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "testhud.lua" )
local open = false
include ( 'shared.lua' )
local open = false
function GM:PlayerInitialSpawn(ply)
if(ply:GetPData("playerLvl") == nil) then
ply:SetNWInt("playerLvl", 1)
else
ply:SetNWInt("playerLvl", ply:GetPData("playerLvl"))
end
if(ply:GetPData("playerExp") == nil) then
ply:SetNWInt("playerExp", 0)
else
ply:SetNWInt("playerExp", ply:GetPData("playerExp"))
end
if(ply:GetPData("playerMoney") == nil) then
ply:SetNWInt("playerMoney", 0)
else
ply:SetNWInt("playerMoney", ply:GetPData("playerMoney"))
end
end
function GM:OnNPCKilled(npc, attacker, inflictor)
attacker:SetNWInt("playerMoney", attacker:GetNWInt("playerMoney") + 100)
attacker:SetNWInt("playerExp", attacker:GetNWInt("playerExp") + 100)
checkForLevel(attacker)
end
function GM:PlayerDeath(victim, inflictor, attacker)
attacker:SetNWInt("playerMoney", attacker:GetNWInt("playerMoney") + 100)
attacker:SetNWInt("playerExp", attacker:GetNWInt("playerExp") + 100)
checkForLevel(attacker)
end
function GM:PlayerLoadout(ply)
ply:Give("m9k_l85")
ply:Give("m9k_colt1911")
ply:Give("m9k_knife")
ply:Give("m9k_m61_frag")
ply:GiveAmmo(500, "ar2", true)
ply:GiveAmmo(100, "pistol", true)
return true
end
function checkForLevel(ply)
local expToLevel = (ply:GetNWInt("playerLvl") * 100) * 2
local curExp = ply:GetNWInt("playerExp")
local curLvl = ply:GetNWInt("playerLvl")
if(curExp >= expToLevel) then
curExp = curExp - expToLevel
ply:SetNWInt("playerExp", curExp)
ply:SetNWInt("playerLvl", curLvl + 1)
end
end
function GM:PlayerDisconnected(ply)
ply:SetPData("playerExp", ply:GetNWInt("playerExp"))
ply:SetPData("playerLvl", ply:GetNWInt("playerLvl"))
ply:SetPData("playerMoney", ply:GetNWInt("playerMoney"))
end
function GM:ShutDown()
for k, v in pairs(player.GetAll()) do
v:SetPData("playerExp", v:GetNWInt("playerExp"))
v:SetPData("playerLvl", v:GetNWInt("playerLvl"))
v:SetPData("playerMoney", v:GetNWInt("playerMoney"))
end
end
function GM:ShowSpare2(ply)
ply:ConCommand("open_game_menu")
end
Thanks!
-Graham

You call
concommand.Add("open_game_menu", gameMenu())
which calls addButtons(Menu) which is nil at this point as the function definition follows after concommand.Add("open_game_menu", gameMenu()).
It's all there. You just have to read the error message.
Change the order in your script to fix the error.

Related

Is it possible to drag and drop polygon blocks with the mouse?

I am practicing simple lua programming with love2d.
What about the code that enables mouse drag and drop of polygon blocks here?
function love.load()
b1 = {}
mouse = {}
love.physics.setMeter(70)
world = love.physics.newWorld(0, 9.81*64, true)
objects = {}
objects.ground = {}
objects.ground.body = love.physics.newBody(world, 700/2, 660)
objects.ground.shape = love.physics.newRectangleShape(650, 50)
objects.ground.fixture = love.physics.newFixture(objects.ground.body,objects.ground.shape)
objects.lwall = {}
objects.lwall.body = love.physics.newBody(world, 0, 350)
objects.lwall.shape = love.physics.newRectangleShape(50, 6500)
objects.lwall.fixture = love.physics.newFixture(objects.lwall.body,objects.lwall.shape)
objects.rwall = {}
objects.rwall.body = love.physics.newBody(world, 700, 350)
objects.rwall.shape = love.physics.newRectangleShape(50, 6500)
objects.rwall.fixture = love.physics.newFixture(objects.rwall.body,objects.rwall.shape)
objects.block1 = {}
objects.block1.body = love.physics.newBody(world, 200, 300, "dynamic")
objects.block1.shape = love.physics.newRectangleShape(0, 0, 162.5,32.5)
objects.block1.fixture = love.physics.newFixture(objects.block1.body, objects.block1.shape, 5)
objects.block2 = {}
objects.block2.body = love.physics.newBody(world, 200, 350, "dynamic")
objects.block2.shape = love.physics.newRectangleShape(0, 0, 162.5,32.5)
objects.block2.fixture = love.physics.newFixture(objects.block2.body, objects.block2.shape, 2)
objects.block3 = {}
objects.block3.body = love.physics.newBody(world, 200, 400, "dynamic")
objects.block3.shape = love.physics.newRectangleShape(0, 0, 162.5,32.5)
objects.block3.fixture = love.physics.newFixture(objects.block3.body, objects.block3.shape, 5)
objects.block4 = {}
objects.block4.body = love.physics.newBody(world, 200, 450, "dynamic")
objects.block4.shape = love.physics.newRectangleShape(0, 0, 162.5,32.5)
objects.block4.fixture = love.physics.newFixture(objects.block4.body, objects.block4.shape, 5)
objects.block5 = {}
objects.block5.body = love.physics.newBody(world, 200, 500, "dynamic")
objects.block5.shape = love.physics.newRectangleShape(0, 0, 162.5,32.5)
objects.block5.fixture = love.physics.newFixture(objects.block5.body, objects.block5.shape, 5)
objects.block6 = {}
objects.block6.body = love.physics.newBody(world, 200, 550, "dynamic")
objects.block6.shape = love.physics.newRectangleShape(0, 0, 162.5,32.5)
objects.block6.fixture = love.physics.newFixture(objects.block6.body, objects.block6.shape, 5)
objects.block7 = {}
objects.block7.body = love.physics.newBody(world, 200, 600, "dynamic")
objects.block7.shape = love.physics.newRectangleShape(0, 0, 162.5,32.5)
objects.block7.fixture = love.physics.newFixture(objects.block7.body, objects.block7.shape, 5)
love.graphics.setBackgroundColor(0, 0, 0)
love.window.setMode(700, 650)
end
function getMouse()
local isDown = love.mouse.isDown(1,2)
return x, y, isDown
end
function love.update(dt)
world:update(dt)
mouse.x, mouse.y = love.mouse.getPosition()
objects.block1.x, objects.block1.y = objects.block1.body:getPosition()
if love.keyboard.isDown("d") then
objects.block1.body:applyForce(4000, 0)
objects.block1.body:applyTorque(100000)
if love.keyboard.isDown("w") then
objects.block1.body:applyForce(0, -150000)
objects.block1.body:setLinearVelocity(0, 0)
end
elseif love.keyboard.isDown("a") then
objects.block1.body:applyForce(-4000, 0)
objects.block1.body:applyTorque(-100000)
if love.keyboard.isDown("w") then
objects.block1.body:applyForce(0, -150000)
objects.block1.body:setLinearVelocity(0, 0)
end
elseif love.keyboard.isDown("w") then
objects.block1.body:applyForce(0, -350000)
objects.block1.body:setLinearVelocity(0, 0)
elseif love.keyboard.isDown("s") then
objects.block1.body:applyForce(0, 350000)
objects.block1.body:setLinearVelocity(0, 0)
end
if love.keyboard.isDown("l") then
objects.block2.body:applyForce(4000, 0)
elseif love.keyboard.isDown("j") then
objects.block2.body:applyForce(-4000, 0)
elseif love.keyboard.isDown("i") then
objects.block2.body:applyForce(0, -150000)
objects.block2.body:setLinearVelocity(0, 0)
end
if objects.block1.body:getPosition() == love.mouse.getPosition() then
if love.mouse.isDown(1) then
objects.block1.x = objects.block1.x - 700
objects.block1.y = objects.block1.y - 650
end
end
end
function love.draw()
love.graphics.setColor(0.7, 0.7, 0.7)
love.graphics.polygon("fill", objects.ground.body:getWorldPoints(objects.ground.shape:getPoints()))
love.graphics.polygon("fill", objects.lwall.body:getWorldPoints(objects.lwall.shape:getPoints()))
love.graphics.polygon("fill", objects.rwall.body:getWorldPoints(objects.rwall.shape:getPoints()))
love.graphics.setColor(0.95, 0.5, 0.1)
love.graphics.polygon("fill", objects.block1.body:getWorldPoints(objects.block1.shape:getPoints()))
love.graphics.polygon("fill", objects.block2.body:getWorldPoints(objects.block2.shape:getPoints()))
love.graphics.polygon("fill", objects.block3.body:getWorldPoints(objects.block1.shape:getPoints()))
love.graphics.polygon("fill", objects.block4.body:getWorldPoints(objects.block2.shape:getPoints()))
love.graphics.polygon("fill", objects.block5.body:getWorldPoints(objects.block1.shape:getPoints()))
love.graphics.polygon("fill", objects.block6.body:getWorldPoints(objects.block2.shape:getPoints()))
love.graphics.polygon("fill", objects.block7.body:getWorldPoints(objects.block1.shape:getPoints()))
love.graphics.setColor(1, 1, 1)
love.graphics.print("Mouse locate : " .. mouse.x..','..mouse.y)
love.graphics.print("block 1 locate : " .. objects.block1.x..','..objects.block1.y, 200)
end
How can I fix it so that I can drag and drop each polygon block in that code?
(in a similar way to Google Gravity)
I tried to configure the code so that the individual polygon blocks and the current mouse position are the same, and move when left-clicked, but it failed.
You are trying to compare a position (center of object) with the position of the mouse. Both are floats, the chance that you hit exactly the center of your shape is effectively zero.
Instead you might want to check for collision:
if love.mouse.isDown(1) then
local mx, my = love.mouse.getPosition()
mx, my = objects.block1.body:getLocalPoint(mx, my)
if objects.block1.shape:testPoint(mx, my, 0, 0, 0) then
objects.block1.body:setPosition(love.mouse.getPosition())
end
end
I transformed the current mouse position to the position relative to your body. I then checked, if this point collides with the bodies shape. The last three arguments are not properly documented, but it looks like they are offset and rotation.
I then set the position using the bodies setPosition. You tried to set your copy of the position, which won't reflect your change. Notice that setting the position will not reset or modify the velocity, thus if you hold the object, it will still build up velocity due to gravity.
There is still room for improvement, for example, you should hold on the object once pressed, as well as keep the initial offset.

lua/pivohelperv2.lua:127: unexpected symbol near ')'

Pls can u help me, thats not all of the code but in this piece problem. Thats Glua and i hope u help me!!!
local dPanelButton1 = vgui.Create( 'DButton', dPanelDa) --Кнопка для лотки
dPanelButton1:SetSize( 250, 50 )
dPanelButton1:SetPos( 625, 370 )
dPanelButton1:SetText( '' )
dPanelButton1.Paint = function( self, w, h )
draw.RoundedBox( 30, 0, 0, w, h, Color( 90, 90, 90, 200 ) )
draw.SimpleText( "Админский ПивоХелп", "help", w / 2, h / 2.0, Color( 224, 184, 128 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
end
dPanelButton1.DoClick = function()
local dPanelDa = vgui.Create( 'DFrame')
dPanelDa:SetSize( 500, 300 )
dPanelDa:SetPos( ScrW() / 2 - 450, ScrH() / 2 - 250)
dPanelDa:SetTitle( ' Админский ПивоХелп ' )
dPanelDa:ShowCloseButton( true )
dPanelDa:MakePopup()
dPanelDa.Paint = function( self, w, h )
draw.RoundedBox( 5, 0, 0, w, h, Color(90, 90, 90, 200) )
draw.RoundedBox( 5, 2, 2, w, 25, Color(224, 184, 128) )
end
end
timer.Simple( 1, function() PivoDerma() end ) -- потнич
end)
add some more details!add some more details!add some more detailsadd some more detailsadd some more detailsadd some more detailsadd some more detailsadd some more detailsadd some more detailsadd some more detailsadd some more details
You have an extra end) at the end of the code block. I assume that's line 127, right? That is, unless this code is inside a block that starts somewhere we can't see in your except.
Be sure to be careful with identation when writing function blocks! It helps to make sure your function() blocks are properly closed with a corresponding end.
One extra thing. This:
dPanelButton1.Paint = function( self, w, h )
...
end
Can instead be written as:
function dPanelButton1:Paint( w, h )
-- the 'self' arg can be omitted by using colons ":" instead of dot "." during declaration and calls.
-- this is the most common way of passing the table the function is stored in as the first argument, implicitly named `self`.
-- In other words, calling `dPanelButton1:Paint(1, 2)` is the same as calling `dPanelButton1.Paint(dPanelButton1, 1, 2)`
...
end
And this:
dPanelButton1.DoClick = function()
...
end
Could be written as:
function dPanelButton1.DoClick()
-- Writing `function foo(arg)` is the same as writing `foo = function(arg)`.
...
end
This makes the function blocks clearer in the code and is easier for others to read. Clean readable code is how you prevent syntax errors (well, that and an IDE).

GLua - part of the string library

I have gui wherein I need show information from table
When I open gui, I have this error:
"attempt to index a string value with bad key ('Index' is not part of the string library)"
SH file. In this file I put table information
MyList = {}
MyList = {
Index = 1,
Name = "Name 1",
Class = "exampleclass",
Description = "Desc 1",
Model = "modelname",
Color = Color(255, 255, 255, 255)
}
CL file. This file contains the part of the code where the error occurs. The error occurs on the first line
for k, v in SortedPairsByMemberValue( MyList, "Index" ) do
if v.Class == "exampleclass" then
local mainbuttons = vgui.Create( "DCollapsibleCategory", category )
mainbuttons:Dock(TOP)
mainbuttons:DockMargin(0, 6, 0, 2)
mainbuttons.Header:SetTall(24)
mainbuttons:SetExpanded(0)
mainbuttons:SetLabel("")
mainbuttons.Text = v.Name
function mainbuttons:Paint(w, h)
local h = 24
surface.SetDrawColor(v.Color)
surface.DrawRect(0, 0, w, h)
surface.SetFont("NovuxFont.ArialLight.16")
local textw, texth = surface.GetTextSize(self.Text)
surface.SetTextColor(Color(255, 255, 255))
surface.SetTextPos(16, h / 2 - texth / 2)
surface.DrawText(self.Text)
end
local craftpanel = vgui.Create( "DPanel", mainbuttons )
craftpanel:SetPos( 0, 25 )
craftpanel:SetSize( mainframescroll:GetWide(), 250 )
craftpanel.Paint = function() -- Paint function
surface.SetDrawColor( 65, 65, 65, 0 )
surface.DrawRect( 0, 0, craftpanel:GetWide(), craftpanel:GetTall() )
end
local spoilertext = vgui.Create( "DLabel", mainbuttons )
spoilertext:SetText( v.Description )
spoilertext:SetTextColor( Color( 255, 255, 255 ) )
spoilertext:SetFont( "NovuxFont.ArialLight.16" )
spoilertext:SetPos( 108, 32 )
spoilertext:SetSize( mainframescroll:GetWide(), 25 )
spoilertext.Paint = function( self, w, h )
draw.RoundedBox( 0, 0, 0, w, h, Color( 102, 102, 102, 0 ))
end
local modelframe = vgui.Create( "DModelPanel", mainbuttons )
modelframe:SetPos( 0, 65 )
modelframe:SetSize( 300, 200 )
modelframe:SetModel( v.Model )
modelframe:GetEntity():SetAngles( Angle( -10, 0, 15 ) )
local mn, mx = modelframe.Entity:GetRenderBounds()
local size = 0
size = math.max( size, math.abs( mn.x ) + math.abs( mx.x ) )
size = math.max( size, math.abs( mn.y ) + math.abs( mx.y ) )
size = math.max( size, math.abs( mn.z ) + math.abs( mx.z ) )
modelframe:SetFOV( 45 )
modelframe:SetCamPos( Vector( size, size, size ) )
modelframe:SetLookAt( (mn + mx) * 0.5 )
function modelframe:LayoutEntity( Entity )
return
end
end
end
The problem is that you put the whole item in MyList where by logic of SortedPairsByMemberValue you supposed to put new table inside MyList.
This fixes the problem:
MyList = {
{
Index = 1,
Name = "Name 1",
Class = "exampleclass",
Description = "Desc 1",
Model = "modelname",
Color = Color(255, 255, 255, 255)
}
}
Notice that now this is a nested table.

Lua arrays print results in specified order

function table_merge(t1, t2)
for _, v in ipairs(t2) do
table.insert(t1, v)
end
end
function getMaster(tbl, rules)
local result = false
for _, rule in ipairs(rules) do
for i, v in ipairs(tbl) do
result = v
if tostring(v) ~= tostring(rule) then
result = false
break
end
end
if result then break end
end
return result
end
function start(data, rules)
local master_key, master_val
local _temp, continue = {}, true
for i, tbl in ipairs(data) do
local master = getMaster(tbl, rules)
if master and master ~= master_val then
continue = true
end
if continue then
if master then
master_key = i
master_val = master
elseif tbl[#tbl] == master_val then
tbl[#tbl] = nil
table.insert(_temp[master_key], master_val)
elseif master_key then
continue = false
end
end
_temp[i] = tbl
end
local result = {}
for i, tbl in ipairs(_temp) do
table_merge(result, tbl)
end
return table.concat(result, "")
end
-- RULES
local rules = { 0, 1}
local data = {
{ 0, 0, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 1, 0 },
{ 0, 0, 0, 8, 1, 0 },
{ 1, 1, 1, 1, 8, 8 },
{ 0, 0, 0, 0, 0, 0 },
}
start(data, rules)
OUTPUT:
000000001111100081111188000000
The expected results should be this:
000000001111110008111188000000
How do I achieve the required results? the table can contain more than six elements but initially it is six. so when all the elements are 1, it will check the next immediate Table to see if the last element is also one; if true it removes it and adds to the six making seven, it will then check again for the next immediate table if the last digit is 1, if true it removes that also and adds to the seven making 8. It will check again and if false return to where it left. So here the table whose element were removed become five in number.
So I was hoping that they could satisfy the rule also if all the five elemnts are 1 or 0. But it seems only the six elements satisfy the rule...
I hope it's clear Thanks
function table_merge(t1, t2)
for _, v in ipairs(t2) do
table.insert(t1, v)
end
end
function getMaster(tbl, rules, w)
local result = false
for _, rule in ipairs(rules) do
for i = 1, w do
local v = tbl[i]
result = v
if tostring(v) ~= tostring(rule) then
result = false
break
end
end
if result then break end
end
return result
end
function start(data, rules)
local width = #data[1] -- assuming all data rows have the same width
local master_keys = {}
local master_values = {}
local continue_idx = width + 1
for i, tbl in ipairs(data) do
for w = width, 1, -1 do
if w >= continue_idx and tbl[w] == master_values[w] then
table.insert(data[master_keys[w]], master_values[w])
tbl[w] = nil
else
local master = getMaster(tbl, rules, w)
if master then
master_keys[w] = i
master_values[w] = master
continue_idx = w
else
continue_idx = w + 1
end
break
end
end
end
local result = {}
for i, tbl in ipairs(data) do
table_merge(result, tbl)
end
return table.concat(result, "")
end
-- RULES
local rules = { 0, 1 }
local data = {
{ 0, 0, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 1, 0 },
{ 0, 0, 0, 8, 1, 0 },
{ 1, 1, 1, 1, 8, 8 },
{ 0, 0, 0, 0, 0, 0 },
}
print(start(data, rules))

Even with delay all objects appear in display at once... what do I do?

local path = pather:getPath(startx,starty, endx,endy)
if path then
compPath = display.newGroup();
for node, count in path:nodes() do
--timer.performWithDelay( 1000, function (event)
print(('Step: %d - x: %d - y: %d'):format(count, node:getX(), node:getY()))
local tile = display.newRect((node:getX() * 50) - 25, (node:getY() * 50) - 25, 48, 48)
colorCell(tile, 0, 0, 255)
tile.alpha = 0
usleep(500);
transition.fadeIn( tile, { time=1500 } )
compPath:insert(tile)
--end
--)
end
end
I have this path that I am trying to animate as it appears but it seems to all show at once even with a delay or if I put it in a timer to go in spurts. Do I have to be displaying it using framerate at every second instead?
What am I missing?
You're not incrementing the delay time in the loop, so you're scheduling all your path nodes to show up in 1 second.
Remember, the loop is going to execute almost instantly (computers are fast).
Try this:
if path then
compPath = display.newGroup();
local revealInterval = 500
local revealTimeout = 0
for node, count in path:nodes() do
timer.performWithDelay( revealTimeout, function (event)
local tile = display.newRect((node:getX() * 50) - 25, (node:getY() * 50) - 25, 48, 48)
colorCell(tile, 0, 0, 255)
tile.alpha = 0
transition.fadeIn( tile, { time=1500 } )
compPath:insert(tile)
end
)
revealTimeout = revealTimeout + revealInterval
end
end

Resources