Print Command

My print command at line 120 won’t print the “string_dir” value I want it to. It just prints the text “not moving and last movement was towards”, then nothing. Why?? I can’t figure it out for the life of me. This same command, when used in a similar code, works just fine.
Below are the two codes:
display.setDefault("background",255,255,255)if table.copy == nil then table.copy = function (...) local t = {} for adx, tb in ipairs(arg) do for i = 1, #tb do table.insert(t, tb[i]) end end return t endend-- Bypassing the "you are not using a new enough build" warninglocal loqsprite = require('loq_sprite')local spriteFactory = loqsprite.newFactory('sheet')local player = spriteFactory:newSpriteGroup()atrace(xinspect(player:getSpriteNames()))local prevx = 0local prevy = 0local dragDirectionlocal flag = 0local moved = 0player.x = 300player.y = 500player:play('Player static back view')local string_dir = ''-- text to display directionlocal directionTXT = display.newText("direction: ",50,50,nil,25)directionTXT:setTextColor( 255,0,0 )local function onTouch( event ) local t = event.target local phase = event.phase if "began" == phase then -- Make target the top-most object local parent = t.parent parent:insert( t ) display.getCurrentStage():setFocus( t ) -- Spurious events can be sent to the target, e.g. the user presses -- elsewhere on the screen and then moves the finger over the target. -- To prevent this, we add this flag. Only when it's true will "move" -- events be sent to the target. t.isFocus = true -- Store initial position t.x0 = event.x - t.x t.y0 = event.y - t.y prevx = event.x prevy = event.y elseif t.isFocus then if "moved" == phase then flag = 1 -- Make object move (we subtract t.x0,t.y0 so that moves are -- relative to initial grab point, rather than object "snapping"). t.x = event.x - t.x0 t.y = event.y - t.y0 local dx = prevx - event.x local dy = prevy - event.y local distance = dx * dx + dy * dy if distance>400 then local angle = math.atan2(dy,dx) * 57.2957795 local string_dir if angle>=45*-1 and angle<=45 then string_dir="Left" if dragDirection ~= "left" then player:play('Player run side view left') dragDirection = "left" end elseif angle>45 and angle<135 then string_dir="Up" if dragDirection ~= "up" then player:play('Player run back view') dragDirection = "up" end elseif angle>135*-1 and angle<45*-1 then string_dir="Down" if dragDirection ~= "down" then player:play('Player run front view') dragDirection = "down" end elseif angle>=135 or angle<=135*-1 then string_dir="Right" if dragDirection ~= "right" then player:play('Player run side view right') dragDirection = "right" end end prevx=event.x prevy=event.y directionTXT.text = "Direction : "..string_dir moved = moved + 1 end elseif "ended" == phase or "cancelled" == phase then display.getCurrentStage():setFocus( nil ) t.isFocus = false flag = 0 end end -- Important to return true. This tells the system that the event -- should not be propagated to listeners of any objects underneath. return trueendlocal function movementTracker(event) if flag == 0 then return true end if moved == 0 then print("not moving and last movement was towards "..string_dir) end moved = 0endplayer:addEventListener( "touch", onTouch )Runtime:addEventListener("enterFrame", movementTracker)[/code]The same command as line 120 is at line 72 in this second example, only in this one it works properly.--to store previous position of x and y local prevx = 0local prevy = 0 local circle = display.newCircle(250, 250, 50)-- text to display directionlocal directionTXT = display.newText("direction: ",50,50,nil,25) local flag = 0local moved = 0local function onTouch( event ) local t = event.target local phase = event.phase if "began" == phase then -- Make target the top-most object local parent = t.parent parent:insert( t ) display.getCurrentStage():setFocus( t ) t.isFocus = true -- Store initial position t.x0 = event.x - t.x t.y0 = event.y - t.y prevx = event.x prevy = event.y elseif t.isFocus then if "moved" == phase then flag = 1 t.x = event.x - t.x0 t.y = event.y - t.y0 local dx = prevx - event.x local dy = prevy - event.y local distance = dx * dx + dy * dy if distance>400 then local angle = math.atan2(dy,dx) * 57.2957795 if angle>=22*-1 and angle<23 then string_dir="Left" elseif angle>=23 and angle<68 then string_dir="Up Left" elseif angle>=68 and angle<113 then string_dir="Up" elseif angle>=113 and angle<158 then string_dir="Up Right" elseif angle>=135 or angle<157*-1 then string_dir="Right" elseif angle>=157*-1 and angle<112*-1 then string_dir="Down Right" elseif angle>=112*-1 and angle<67*-1 then string_dir="Down"; elseif angle>=67*-1 and angle<22*-1 then string_dir="Down Left" end prevx=event.x prevy=event.y directionTXT.text = "Direction : "..string_dir moved = moved + 1 end else if "ended" == phase then flag = 0 end end end return trueend local prevMoved = 0local function movementTracker(event) if flag == 0 then return true end if moved == 0 then print("not moving and last movement was towards "..string_dir) end moved = 0end circle:addEventListener("touch", onTouch)Runtime:addEventListener("enterFrame", movementTracker)[/code] [import]uid: 79394 topic_id: 13547 reply_id: 313547[/import]

could you delete line no 72 and chk again also what is

local loqsprite = require(‘loq_sprite’)

it is preventing me chk this code got the error about this and i can’t see anything [import]uid: 12482 topic_id: 13547 reply_id: 49760[/import]

remove line 72: local string_dir
as you are redeclaring the variable as local within the function [import]uid: 49842 topic_id: 13547 reply_id: 49776[/import]

@hgvyas123 OMG, you’re right, I totally missed that. Deleting it worked like a charm, and now it’s running great.

local loqsprite = require(‘loq_sprite’) is an API of the loqsprite program I use to create and import spritesheets for my animation.

Thanks so much for your help!
[import]uid: 79394 topic_id: 13547 reply_id: 49891[/import]

@idealconceptz Yeap, removing it did the trick all right! Also, totally appreciate the explanation of the theory behind my blunder, I’d be left wondering (albeit with a working code) without it. Cheers! [import]uid: 79394 topic_id: 13547 reply_id: 49892[/import]