Problem with timer and shake effect

Hi, I have a problem with the timer and shake effect. And I’m using the following code:

module(..., package.seeall)  
  
--====================================================================--  
-- SCENE: [NAME]  
--====================================================================--  
  
--[[  
  
 - Version: [1.0]  
 - Made by: [name]  
 - Website: [url]  
 - Mail: [mail]  
  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
 - INFORMATION  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
  
 - [Your info here]  
  
--]]  
  
new = function ()  
  
 ------------------  
 -- Groups  
 ------------------  
  
 local localGroup = display.newGroup()  
  
 ------------------  
 -- Your code here  
 ------------------  
  
 local indextext = display.newImageRect( "assets/indextext.png", 402, 40 );  
 indextext.x = display.contentWidth / 2; indextext.y = 30;  
  
  
 --local ui = require("ui");  
 local gtween = require("gtween");  
 local words = require("words");  
 require("retinaText");   
  
 local platformName = system.getInfo( "platformName");  
  
 system.setAccelerometerInterval( 90 ) -- Drains battery, 100 max, 10 min  
  
 local background = display.newImage("background-large.png",true);  
 background.x = display.contentWidth / 2;  
 background.y = display.contentHeight / 2;  
  
 localGroup:insert(background);  
 localGroup:insert(indextext);  
  
 --------------------------------------------------  
 -- Skriver bara ut alla tillgängliga system fonter  
 -------------------------------------------------  
 --[[local sysFonts = native.getFontNames()  
 for k,v in pairs(sysFonts) do   
 print("Fontnamn:"..v)  
 end]]--  
  
  
 \_W = display.contentWidth  
 \_H = display.contentHeight  
  
 local chatbubbleCollisionFilter = { categoryBits = 2, maskBits = 1 }  
 local wallCollisionFilter = { categoryBits = 1, maskBits = 3 }  
  
 local physics = require("physics");  
 physics.start();  
 --physics.setDrawMode( "hybrid" );  
 physics.setScale( 40 );  
 physics.setGravity( 0, 0 );   
  
  
 local function autoWrappedText(text, font, size, color, width)  
 --print("text: " .. text)  
 local sizeMultiply2 = 1 / display.contentScaleY; --Denna fixer så textrutan kan bli dubbelt så stor vid retina skärm etc  
 print ("Scale Y/X: "..display.contentScaleY.." "..display.contentScaleX);  
 width = width\*sizeMultiply2;  
  
 if text == '' then return false end  
 font = font or native.systemFont  
 size = tonumber(size) or 12  
 color = color or {255, 255, 255}  
 width = width or display.stageWidth  
  
 local result = display.newGroup()  
 local lineCount = 0  
 -- do each line separately  
 for line in string.gmatch(text, "[^\n]+") do  
 local currentLine = ''  
 local currentLineLength = 0 -- the current length of the string in chars  
 local currentLineWidth = 0 -- the current width of the string in pixs  
 local testLineLength = 0 -- the target length of the string (starts at 0)  
 -- iterate by each word  
 for word, spacer in string.gmatch(line, "([^%s%-]+)([%s%-]\*)") do  
 local tempLine = currentLine..word..spacer  
 local tempLineLength = string.len(tempLine)  
 -- test to see if we are at a point to try to render the string  
 if testLineLength \> tempLineLength then  
 currentLine = tempLine  
 currentLineLength = tempLineLength  
 else  
 -- line could be long enough, try to render and compare against the max width  
 local tempDisplayLine = display.newText(tempLine, 0, 0, font, size)  
 local tempDisplayWidth = tempDisplayLine.width  
 tempDisplayLine:removeSelf();  
 tempDisplayLine=nil;  
 if tempDisplayWidth \<= width then  
 -- line not long enough yet, save line and recalculate for the next render test  
 currentLine = tempLine  
 currentLineLength = tempLineLength  
 testLineLength = math.floor((width\*0.9) / (tempDisplayWidth/currentLineLength))  
 else  
 -- line long enough, show the old line then start the new one  
 local newDisplayLine = display.newText(currentLine, 0, (size \* 1.0) \* (lineCount - 1), font, size)  
 newDisplayLine.x = width/2 - newDisplayLine.width/2\*display.contentScaleX; --Denna linje gör så att texten blir centrererad, vi lägger till och skalar med display.contentScaleX så det passar Retina skärmar etc.  
 print ("LineX:"..newDisplayLine.x.." / "..newDisplayLine.width);  
 newDisplayLine:setTextColor(color[1], color[2], color[3])  
 result:insert(newDisplayLine)  
 lineCount = lineCount + 1  
 currentLine = word..spacer  
 currentLineLength = string.len(word)  
 end  
 end  
 end  
 -- finally display any remaining text for the current line  
 local newDisplayLine = display.newText(currentLine, 0, (size \* 1.0) \* (lineCount - 1), font, size);  
 newDisplayLine.x = width/2 - newDisplayLine.width/2\*display.contentScaleX; --Denna linje gör så att texten blir centrererad, vi lägger till och skalar med display.contentScaleX så det passar Retina skärmar etc.  
 print ("LineX:"..newDisplayLine.x);  
  
 newDisplayLine:setTextColor(color[1], color[2], color[3])  
 result:insert(newDisplayLine)  
 lineCount = lineCount + 1  
 currentLine = ''  
 currentLineLength = 0  
 end  
 result:setReferencePoint(display.CenterReferencePoint)  
 return result  
 end  
  
 ---------------------------  
 -- ChatBubbles  
 ---------------------------  
 local pratbubbla = {};  
 pratbubbla.density = 0.2; pratbubbla.friction = 0.2; pratbubbla.bounce = 0.5;  
  
 local pratbubbla11\_shape1 = { 0,-19, 25,-12, 33,3, 10,18, -22,16, -32,-3, -17,-16 };  
 local pratbubbla11\_org = display.newImageRect( "assets/pratbubbla11\_org.png", 73, 47 );  
 local pratbubbla11\_gro = display.newGroup();  
 localGroup:insert(pratbubbla11\_gro);  
 pratbubbla11\_gro:insert(pratbubbla11\_org);  
 pratbubbla11\_gro:setReferencePoint( display.TopLeftReferencePoint );  
 pratbubbla11\_gro.x = 185;  
 pratbubbla11\_gro.y = 252;  
 physics.addBody( pratbubbla11\_gro, "dynamic",   
 { density=pratbubbla.density, friction=pratbubbla.friction, bounce=pratbubbla.bounce, shape=pratbubbla11\_shape1, filter=chatbubbleCollisionFilter }  
 );  
 pratbubbla11\_gro.isFixedRotation = true;  
  
 local pratbubbla10\_shape1 = { 0,-13, 18,-8, 24,4, 5,13, -15,10, -23,-1, -12,-11 };  
 local pratbubbla10\_org = display.newImageRect( "assets/pratbubbla10\_org.png", 52, 34 );  
 local pratbubbla10\_gro = display.newGroup();  
 localGroup:insert(pratbubbla10\_gro);  
 pratbubbla10\_gro:insert(pratbubbla10\_org);  
 pratbubbla10\_gro:setReferencePoint( display.TopLeftReferencePoint );  
 pratbubbla10\_gro.x = 360;  
 pratbubbla10\_gro.y = 220;  
 physics.addBody( pratbubbla10\_gro, "dynamic",   
 { density=pratbubbla.density, friction=pratbubbla.friction, bounce=pratbubbla.bounce, shape=pratbubbla10\_shape1, filter=chatbubbleCollisionFilter }  
 );  
 pratbubbla10\_gro.isFixedRotation = true;  
  
 local pratbubbla8\_shape1 = { 1,-20, 29,-11, 32,13, 5,20, -26,13, -30,-10, -16,-20 };  
 local pratbubbla8\_org = display.newImageRect( "assets/pratbubbla8\_org.png", 74, 48 );  
 local pratbubbla8\_gro = display.newGroup();  
 localGroup:insert(pratbubbla8\_gro);  
 pratbubbla8\_gro:insert(pratbubbla8\_org);  
 pratbubbla8\_gro:setReferencePoint( display.TopLeftReferencePoint );  
 pratbubbla8\_gro.x = 208;  
 pratbubbla8\_gro.y = 69;  
 physics.addBody( pratbubbla8\_gro, "dynamic",   
 { density=pratbubbla.density, friction=pratbubbla.friction, bounce=pratbubbla.bounce, shape=pratbubbla8\_shape1, filter=chatbubbleCollisionFilter }  
 );  
 pratbubbla8\_gro.isFixedRotation = true;  
  
 local pratbubbla6\_shape1 = { 1,-23, 31,-13, 38,9, 8,25, -31,14, -37,-7, -19,-20 };  
 local pratbubbla6\_org = display.newImageRect( "assets/pratbubbla6\_org.png", 82, 53 );  
 local pratbubbla6\_gro = display.newGroup();  
 localGroup:insert(pratbubbla6\_gro);  
 pratbubbla6\_gro:insert(pratbubbla6\_org);  
 pratbubbla6\_gro:setReferencePoint( display.TopLeftReferencePoint );  
 pratbubbla6\_gro.x = 43;  
 pratbubbla6\_gro.y = 187;  
 physics.addBody( pratbubbla6\_gro, "dynamic",   
 { density=pratbubbla.density, friction=pratbubbla.friction, bounce=pratbubbla.bounce, shape=pratbubbla6\_shape1, filter=chatbubbleCollisionFilter }  
 );  
 pratbubbla6\_gro.isFixedRotation = true;  
  
 local pratbubbla4\_shape1 = { -13,-39, 25,-31, 49,-9, 36,24, -35,36, -74,11, -64,-25 };  
 local pratbubbla4\_org = display.newImageRect( "assets/pratbubbla4\_org.png", 161, 84 );  
 local pratbubbla4\_sha = display.newImageRect( "assets/pratbubbla4\_sha.png", 161, 84 );  
 local pratbubbla4\_gro = display.newGroup();  
 localGroup:insert(pratbubbla4\_gro);  
 pratbubbla4\_gro:insert(pratbubbla4\_sha);  
 pratbubbla4\_gro:insert(pratbubbla4\_org);  
 pratbubbla4\_gro:setReferencePoint( display.TopLeftReferencePoint );  
 pratbubbla4\_gro.x = 245;  
 pratbubbla4\_gro.y = 197;  
 physics.addBody( pratbubbla4\_gro, "dynamic",  
 { density=pratbubbla.density, friction=pratbubbla.friction, bounce=pratbubbla.bounce, shape=pratbubbla4\_shape1, filter=chatbubbleCollisionFilter }  
 );  
 pratbubbla4\_gro.isFixedRotation = true;  
  
 --Nä man kanske skulle skola om sig  
 local pratbubbla2\_shape1 = { -12,-81, 81,-55, 89,21, -55,53, -129,-8, -79,-68 };  
 local pratbubbla2\_org = display.newImageRect( "assets/pratbubbla2\_org.png", 264, 171 );  
 local pratbubbla2\_sha = display.newImageRect( "assets/pratbubbla2\_sha.png", 264, 171 );  
 local pratbubbla2\_gro = display.newGroup();  
 localGroup:insert(pratbubbla2\_gro);  
 pratbubbla2\_gro:insert(pratbubbla2\_sha);  
 pratbubbla2\_gro:insert(pratbubbla2\_org);  
 pratbubbla2\_gro:setReferencePoint( display.TopLeftReferencePoint );  
 pratbubbla2\_gro.x = 82;  
 pratbubbla2\_gro.y = 120;  
 physics.addBody( pratbubbla2\_gro, "dynamic",   
 { density=pratbubbla.density, friction=pratbubbla.friction, bounce=pratbubbla.bounce, shape=pratbubbla2\_shape1, filter=chatbubbleCollisionFilter }  
 );  
 pratbubbla2\_gro.isFixedRotation = true;  
  
 local pratbubbla3\_shape1 = { -9,-58, 52,-38, 65,-2, 17,31, -46,32, -76,13, -81,-25, -55,-48 };  
 local pratbubbla3\_org = display.newImageRect( "assets/pratbubbla3\_org.png", 176, 119 );  
 local pratbubbla3\_sha = display.newImageRect( "assets/pratbubbla3\_sha.png", 176, 119 );  
 local pratbubbla3\_gro = display.newGroup();  
 localGroup:insert(pratbubbla3\_gro);  
 pratbubbla3\_gro:insert(pratbubbla3\_sha);  
 pratbubbla3\_gro:insert(pratbubbla3\_org);  
 pratbubbla3\_gro:setReferencePoint( display.TopLeftReferencePoint );  
 pratbubbla3\_gro.x = 20;  
 pratbubbla3\_gro.y = 86;  
 physics.addBody( pratbubbla3\_gro, "dynamic",  
 { density=pratbubbla.density, friction=pratbubbla.friction, bounce=pratbubbla.bounce, shape=pratbubbla3\_shape1, filter=chatbubbleCollisionFilter }  
 );  
 pratbubbla3\_gro.isFixedRotation = true;  
  
 --Kan man bli beläst av en ljudbok?  
 local pratbubbla9\_shape1 = { 2,-23, 24,-13, 15,3, -9,2, -21,-9, -13,-21 };  
 local pratbubbla9\_org = display.newImageRect( "assets/pratbubbla9\_org.png", 53, 52 );  
 local pratbubbla9\_sha = display.newImageRect( "assets/pratbubbla9\_sha.png", 53, 52 );  
 local pratbubbla9\_gro = display.newGroup();  
 localGroup:insert(pratbubbla9\_gro);  
 pratbubbla9\_gro:insert(pratbubbla9\_sha);  
 pratbubbla9\_gro:insert(pratbubbla9\_org);  
 pratbubbla9\_gro:setReferencePoint( display.TopLeftReferencePoint );  
 pratbubbla9\_gro.x = 136;  
 pratbubbla9\_gro.y = 86;  
 physics.addBody( pratbubbla9\_gro, "dynamic",  
 { density=pratbubbla.density, friction=pratbubbla.friction, bounce=pratbubbla.bounce, shape=pratbubbla9\_shape1, filter=chatbubbleCollisionFilter }  
 );  
 pratbubbla9\_gro.isFixedRotation = true;  
  
 local pratbubbla1\_shape1 = { 0,-74, 73,-60, 116,-3, 42,57, -61,56, -114,11, -103,-35, -58,-67 };  
 local pratbubbla1\_org = display.newImageRect( "assets/pratbubbla1\_org.png", 239, 157 );  
 local pratbubbla1\_sha = display.newImageRect( "assets/pratbubbla1\_sha.png", 239, 157 );  
 local pratbubbla1\_gro = display.newGroup();  
 localGroup:insert(pratbubbla1\_gro);  
 pratbubbla1\_gro:insert(pratbubbla1\_sha);  
 pratbubbla1\_gro:insert(pratbubbla1\_org);  
 pratbubbla1\_gro:setReferencePoint( display.TopLeftReferencePoint );  
 pratbubbla1\_gro.x = 211;  
 pratbubbla1\_gro.y = 71;  
 physics.addBody( pratbubbla1\_gro, "dynamic",  
 { density=pratbubbla.density, friction=pratbubbla.friction, bounce=pratbubbla.bounce, shape=pratbubbla1\_shape1, filter=chatbubbleCollisionFilter }  
 );  
 pratbubbla1\_gro.isFixedRotation = true;  
  
 local pratbubbla7\_shape1 = { 0,-34, 36,-25, 45,1, 18,19, -26,17, -42,-4, -29,-29 };  
 local pratbubbla7\_org = display.newImageRect( "assets/pratbubbla7\_org.png", 95, 75 );  
 local pratbubbla7\_sha = display.newImageRect( "assets/pratbubbla7\_sha.png", 95, 75 );  
 local pratbubbla7\_gro = display.newGroup();  
 localGroup:insert(pratbubbla7\_gro);  
 pratbubbla7\_gro:insert(pratbubbla7\_sha);  
 pratbubbla7\_gro:insert(pratbubbla7\_org);  
 pratbubbla7\_gro:setReferencePoint( display.TopLeftReferencePoint );  
 pratbubbla7\_gro.x = 373;  
 pratbubbla7\_gro.y = 53;  
 physics.addBody( pratbubbla7\_gro, "dynamic",  
 { density=pratbubbla.density, friction=pratbubbla.friction, bounce=pratbubbla.bounce, shape=pratbubbla7\_shape1, filter=chatbubbleCollisionFilter }  
 );  
 pratbubbla7\_gro.isFixedRotation = true;  
  
  
 local pratbubbla5\_shape1 = { -8,-45, 24,-38, 46,-14, 35,10, -13,22, -54,6, -59,-21, -38,-37 };  
 local pratbubbla5\_org = display.newImageRect( "assets/pratbubbla5\_org.png", 129, 95 );  
 local pratbubbla5\_sha = display.newImageRect( "assets/pratbubbla5\_sha.png", 129, 95 );  
 local pratbubbla5\_gro = display.newGroup();  
 localGroup:insert(pratbubbla5\_gro);  
 pratbubbla5\_gro:insert(pratbubbla5\_sha);  
 pratbubbla5\_gro:insert(pratbubbla5\_org);  
 pratbubbla5\_gro:setReferencePoint( display.TopLeftReferencePoint );  
 pratbubbla5\_gro.x = 178;  
 pratbubbla5\_gro.y = 153;  
 physics.addBody( pratbubbla5\_gro, "dynamic",  
 { density=pratbubbla.density, friction=pratbubbla.friction, bounce=pratbubbla.bounce, shape=pratbubbla5\_shape1, filter=chatbubbleCollisionFilter }  
 );  
 pratbubbla5\_gro.isFixedRotation = true;  
  
 local pratbubblaLarge = display.newImageRect( "assets/pratbubbla\_large.png", 432, 294 );  
 --pratbubblaLarge:setReferencePoint( display.TopLeftReferencePoint );  
 local pratbubblaLarge\_gro = display.newGroup();  
 localGroup:insert(pratbubblaLarge\_gro);  
 pratbubblaLarge\_gro:insert(pratbubblaLarge);  
 pratbubblaLarge\_gro.x = 240; pratbubblaLarge\_gro.y = 150;  
 pratbubblaLarge\_gro.isVisible = false;  
  
 ---------------------------  
 -- Walls, outside of the viewable area.  
 ---------------------------  
 --display.newRect(x,y,width,height)  
 \_W2 = display.screenOriginX;  
 \_H2 = display.screenOriginY;  
 local top = display.newRect(-200,-50+display.screenOriginX,960,10);  
 localGroup:insert(top);  
 physics.addBody(top, "static", { friction=0, bounce=0.5, filter=wallCollisionFilter})  
 top.name = "top";  
 local left = display.newRect(-50+display.screenOriginX,-200,10, 640)  
 localGroup:insert(left);   
 physics.addBody(left, "static", { friction=0, bounce=0.5, filter=wallCollisionFilter})  
 left.name = "left";  
 local bottom = display.newRect(-200,\_H+50-display.screenOriginX,960, 10)  
 localGroup:insert(bottom);   
 physics.addBody(bottom, "static", { friction=0, bounce=0.5, filter=wallCollisionFilter})  
 bottom.name = "bottom";  
 local right = display.newRect(\_W+50-display.screenOriginX,-200, 10, 640)  
 localGroup:insert(right);   
 physics.addBody(right, "static", { friction=0, bounce=0.5, filter=wallCollisionFilter})  
 right.name = "right";  
  
 ---------------------------  
 -- BottomBar with buttons  
 ---------------------------  
 --local bottomBar = display.newImageRect("assets/bottombar.png",480,40);  
 local bottomBar = display.newImage("assets/bottombar-long.png", true);  
 localGroup:insert(bottomBar);  
 bottomBar:setReferencePoint( display.CenterReferencePoint );  
 bottomBar.x = display.contentWidth / 2;  
 bottomBar.y = display.contentHeight - 19;  
 --bottomBar.x = 0; bottomBar.y = 320-39;  
  
 --Appstore/Android Market link  
 local storeLink = display.newGroup();  
 localGroup:insert(storeLink);  
 local storeLink\_txt = display.newText("JM:s bostadsapp", 40, -11, "Gill Alt One MT", 13);  
 storeLink\_txt:setReferencePoint( display.TopLeftReferencePoint );  
  
 --[[local storeLink\_line = display.newLine( 0,-110, 85,-110 )  
 storeLink\_line:setColor( 255, 255, 255, 255 )  
 storeLink\_line.width = 1;  
 storeLink\_line.x = 40;  
 storeLink\_line.y = storeLink\_txt.y+storeLink\_txt.height\*display.contentScaleX-2; --En specialare för att veta vart strecket ska sitta. Vi använder contentScaleX för att positionera strecket utifrån textens höjd.  
 ]]--  
  
 --Pick the right icon  
 local storeLink\_ico = {};  
 if platformName == "iPhone OS" then  
 storeLink\_ico = display.newImageRect("assets/icon-appstore.png", 28, 28);  
 storeLink\_ico.x = 20;  
 elseif platformName == "Android" then  
 storeLink\_ico = display.newImageRect("assets/icon-androidmarket.png", 28, 28);  
 storeLink\_ico.x = 20;  
 else  
 storeLink\_ico = display.newImageRect("assets/icon-androidmarket.png", 28, 28);  
 storeLink\_ico.x = 20;  
 end  
  
 storeLink:insert(storeLink\_txt);  
 storeLink:insert(storeLink\_ico);  
 --storeLink:insert(storeLink\_line);  
 storeLink.y = 301;  
 storeLink.x = 0+display.screenOriginX; --screenOriginX används för att flytta till kanterna, innehåller överflödet från original upplösningen.  
  
 --Homepage link  
 local siteLink = display.newGroup();  
 localGroup:insert(siteLink);  
 local siteLink\_txt = display.newText("JM:s hemsida", 20, -11, "Gill Alt One MT", 13);  
 siteLink\_txt:setReferencePoint( display.TopLeftReferencePoint );  
  
 --[[local siteLink\_line = display.newLine( 0,-110, 68,-110 )  
 siteLink\_line:setColor( 255, 255, 255, 255 )  
 siteLink\_line.width = 1  
 siteLink\_line.x = 20;  
 siteLink\_line.y = siteLink\_txt.y+siteLink\_txt.height\*display.contentScaleX-2;  
 ]]--  
 local siteLink\_ico = display.newImageRect("assets/icon-jm.png", 20, 28);  
 siteLink\_ico.x = 110; siteLink\_ico.y = 0;  
  
 siteLink:insert(siteLink\_txt);  
 siteLink:insert(siteLink\_ico);  
 --siteLink:insert(siteLink\_line);  
 siteLink.y = 301;  
 siteLink.x = 350-display.screenOriginX;   
  
 ---------------------------  
 -- Misc Buttons  
 ---------------------------  
 --[[local tempButton\_bg = display.newRect(0,0,50,20);  
 local tempButton\_txt = display.newText("Skaka", 8, -2, "Gill Alt One MT", 12);  
 tempButton\_txt:setTextColor(0, 0, 255)  
 local tempButton = display.newGroup();  
 localGroup:insert(tempButton);  
 tempButton:insert(tempButton\_bg);  
 tempButton:insert(tempButton\_txt);]]--  
  
 ---------------------------  
 -- Functions  
 ---------------------------  
 function gotoSite(event)  
 if event.phase == "ended" then  
 system.openURL( "http://www.jm.se/" )   
 end  
 end  
  
 function gotoStore(event)  
 if event.phase == "ended" then  
 if platformName == "iPhone OS" then  
 system.openURL( "http://itunes.apple.com/se/app/jm/id408666502?mt=8" )  
 elseif platformName == "Android" then  
 system.openURL( "https://market.android.com/details?id=com.mis.android.jm" )  
 else  
 system.openURL( "https://market.android.com/details?id=com.mis.android.jm" )  
 end  
 end  
 end  
  
 local function onAccelerate( event )  
 if event.isShake == true then  
 accelerateObjects()   
 end  
 end  
  
 local t = {}  
 function t:timer( event )  
 local transTime = 500;  
 local transAlpha = 0.2;  
 local transDelay = 0;  
 transition.to( pratbubbla11\_gro, { time=transTime, alpha=transAlpha, delay=transDelay} );  
 transition.to( pratbubbla10\_gro, { time=transTime, alpha=transAlpha, delay=transDelay} );  
 transition.to( pratbubbla9\_gro, { time=transTime, alpha=transAlpha, delay=transDelay} );  
 transition.to( pratbubbla8\_gro, { time=transTime, alpha=transAlpha, delay=transDelay} );  
 transition.to( pratbubbla7\_gro, { time=transTime, alpha=transAlpha, delay=transDelay} );  
 transition.to( pratbubbla6\_gro, { time=transTime, alpha=transAlpha, delay=transDelay} );  
 transition.to( pratbubbla5\_gro, { time=transTime, alpha=transAlpha, delay=transDelay} );  
 transition.to( pratbubbla4\_gro, { time=transTime, alpha=transAlpha, delay=transDelay} );  
 transition.to( pratbubbla3\_gro, { time=transTime, alpha=transAlpha, delay=transDelay} );  
 transition.to( pratbubbla2\_gro, { time=transTime, alpha=transAlpha, delay=transDelay} );  
 transition.to( pratbubbla1\_gro, { time=transTime, alpha=transAlpha, delay=transDelay} );  
  
 showLargeBubble = timer.performWithDelay(500, showChatBubble, 1);  
  
 local count = event.count  
 print( "Table listener called " .. count .. " time(s)" )  
 end  
  
 local chatText\_txt = {};  
 function showChatBubble()  
 --[[  
 local chatText = display.newText("Skaka", -150, -50, "GillAltOneMT", 32);  
 chatText:setTextColor(0,0,0);  
 pratbubblaLarge\_gro:insert(chatText);  
 ]]--  
  
 local currentWord = words.randomWord();  
 --autoWrappedText(text, font, size, color, width)  
 --local sizeMultiply2 = 1 / display.contentScaleX; --Denna fixer så textrutan kan bli dubbelt så stor.  
 chatText\_txt = autoWrappedText( currentWord, "Gill Alt One MT", 34, {0,0,0}, 280 );  
 --chatText\_txt:setReferencePoint( display.TopLeftReferencePoint );  
 --chatText\_txt.xScale = 0.5; chatText\_txt.yScale = 0.5;  
  
 if(chatText\_txt.height \> 172) then  
 display.remove( chatText\_txt );  
 chatText\_txt = autoWrappedText( currentWord, "Gill Alt One MT", 24, {0,0,0}, 280 );  
 print("New font size: 24");  
 end  
 chatText\_txt.x = 0; chatText\_txt.y = -15;  
 --print (chatText\_txt.height.." "..chatText\_txt.width);  
  
 --print(pratbubblaLarge\_gro.numChildren);  
 if(pratbubblaLarge\_gro.numChildren \> 1) then --Vi kollar om det innehåller mer än själva bubblan, i så fall tar vi bort den nuvarande texten innan vi lägger dit en ny.  
 pratbubblaLarge\_gro:remove(2);  
 end  
 pratbubblaLarge\_gro:insert(chatText\_txt);  
  
 pratbubblaLarge\_gro.xScale = 0.1;  
 pratbubblaLarge\_gro.yScale = 0.1;  
 --transition.to(pratbubblaLarge, {time=1000, xScale=1, yScale=1,transition=easing.inOutQuad});  
 gtween.new(pratbubblaLarge\_gro, 0.5, {xScale = 1, yScale = 1},{ease = gtween.easing.outBack});  
  
 pratbubblaLarge\_gro.isVisible = true;  
 end  
  
 local timerInfo = {};  
 function accelerateObjects()  
 --print("timerInfo:" ..timerInfo);  
 print( "New Shake" );  
 indextext.isVisible = false;  
 timer.cancel(timerInfo);  
 timerInfo = timer.performWithDelay( 2000, t, 1 );  
 --print("timerInfo:" ..timerInfo);  
  
 pratbubblaLarge\_gro.isVisible = false;  
 local xForce = {};  
 local yForce = {};  
 local minForce = -100;  
 local maxForce = 100;  
 xForce = math.random (minForce, maxForce);  
 yForce = math.random (minForce, maxForce);  
 pratbubbla11\_gro:applyLinearImpulse(xForce,yForce, pratbubbla11\_gro.x, pratbubbla11\_gro.y)  
 pratbubbla11\_gro.linearDamping = 0.3 -- simulates friction of felt  
 pratbubbla11\_gro.alpha = 1;  
  
 xForce = math.random (minForce, maxForce);  
 yForce = math.random (minForce, maxForce);  
 pratbubbla10\_gro:applyLinearImpulse(xForce,yForce, pratbubbla10\_gro.x, pratbubbla10\_gro.y)  
 pratbubbla10\_gro.linearDamping = 0.3 -- simulates friction of felt  
 pratbubbla10\_gro.alpha = 1;  
  
 xForce = math.random (minForce, maxForce);  
 yForce = math.random (minForce, maxForce);  
 pratbubbla9\_gro:applyLinearImpulse(xForce,yForce, pratbubbla9\_gro.x, pratbubbla9\_gro.y)  
 pratbubbla9\_gro.linearDamping = 0.3 -- simulates friction of felt  
 pratbubbla9\_sha.isVisible = false;  
 pratbubbla9\_gro.alpha = 1;   
  
 xForce = math.random (minForce, maxForce);  
 yForce = math.random (minForce, maxForce);   
 pratbubbla8\_gro:applyLinearImpulse(xForce,yForce, pratbubbla8\_gro.x, pratbubbla8\_gro.y)  
 pratbubbla8\_gro.linearDamping = 0.3 -- simulates friction of felt  
 pratbubbla8\_gro.alpha = 1;   
  
 xForce = math.random (minForce, maxForce);  
 yForce = math.random (minForce, maxForce);   
 pratbubbla7\_gro:applyLinearImpulse(xForce,yForce, pratbubbla7\_gro.x, pratbubbla7\_gro.y)  
 pratbubbla7\_gro.linearDamping = 0.3 -- simulates friction of felt  
 pratbubbla7\_sha.isVisible = false;  
 pratbubbla7\_gro.alpha = 1;   
  
 xForce = math.random (minForce, maxForce);  
 yForce = math.random (minForce, maxForce);   
 pratbubbla6\_gro:applyLinearImpulse(xForce,yForce, pratbubbla6\_gro.x, pratbubbla6\_gro.y)  
 pratbubbla6\_gro.linearDamping = 0.3 -- simulates friction of felt  
 pratbubbla6\_gro.alpha = 1;   
  
 xForce = math.random (minForce, maxForce);  
 yForce = math.random (minForce, maxForce);   
 pratbubbla5\_gro:applyLinearImpulse(xForce,yForce, pratbubbla5\_gro.x, pratbubbla5\_gro.y)  
 pratbubbla5\_gro.linearDamping = 0.3 -- simulates friction of felt  
 pratbubbla5\_sha.isVisible = false;  
 pratbubbla5\_gro.alpha = 1;   
  
 xForce = math.random (minForce, maxForce);  
 yForce = math.random (minForce, maxForce);   
 pratbubbla4\_gro:applyLinearImpulse(xForce,yForce, pratbubbla4\_gro.x, pratbubbla4\_gro.y)  
 pratbubbla4\_gro.linearDamping = 0.3 -- simulates friction of felt  
 pratbubbla4\_sha.isVisible = false;  
 pratbubbla4\_gro.alpha = 1;   
  
 xForce = math.random (minForce, maxForce);  
 yForce = math.random (minForce, maxForce);   
 pratbubbla3\_gro:applyLinearImpulse(xForce,yForce, pratbubbla3\_gro.x, pratbubbla3\_gro.y)  
 pratbubbla3\_gro.linearDamping = 0.3 -- simulates friction of felt  
 pratbubbla3\_sha.isVisible = false;  
 pratbubbla3\_gro.alpha = 1;   
  
 xForce = math.random (minForce, maxForce);  
 yForce = math.random (minForce, maxForce);   
 pratbubbla2\_gro:applyLinearImpulse(xForce,yForce, pratbubbla2\_gro.x, pratbubbla2\_gro.y)  
 pratbubbla2\_gro.linearDamping = 0.3 -- simulates friction of felt  
 pratbubbla2\_sha.isVisible = false;  
 pratbubbla2\_gro.alpha = 1;   
  
 xForce = math.random (minForce, maxForce);  
 yForce = math.random (minForce, maxForce);   
 pratbubbla1\_gro:applyLinearImpulse(xForce,yForce, pratbubbla1\_gro.x, pratbubbla1\_gro.y)  
 pratbubbla1\_gro.linearDamping = 0.3 -- simulates friction of felt   
 pratbubbla1\_sha.isVisible = false;  
 pratbubbla1\_gro.alpha = 1;   
 end  
  
 ---------------------------  
 -- Listeners  
 ---------------------------  
 siteLink:addEventListener ("touch", gotoSite);  
 storeLink:addEventListener ("touch", gotoStore);  
 --tempButton:addEventListener ("touch", accelerateObjects)  
 Runtime:addEventListener ("accelerometer", onAccelerate)  
  
 ------------------  
 -- MUST return a display.newGroup()  
 ------------------  
  
 return localGroup  
  
end  

I get the following error message:

New Shake Runtime error ?:0: attempt to perform arithmetic on field '\_time' (a nil value) stack traceback: [C]: ? ?: in function 'cancel' ...1-0479/Applikation-Android-iPhone-v2/scene-shake.lua:507: in function 'accelerateObjects' ...1-0479/Applikation-Android-iPhone-v2/scene-shake.lua:438: in function <...1-0479><br> ?: in function <?:226><br>

If I uncomment the line 507 will work shaker function, but then the bugs depending on how hard you shake the phone. Shaking it quiet so there is no problem, but shake it a little harder so the risk is that it comes up several bubbles right after another. Any suggestions? Please help me! [import]uid: 170055 topic_id: 30186 reply_id: 330186[/import] </…1-0479>

Is the above right, that 507 is;
[lua]chatText_txt.x = 0; chatText_txt.y = -15;[/lua] ?

It’s too much code for me to read but as you say about too many bubbles firing too fast, why not use a timer to prevent it firing more than once every X second/s? [import]uid: 52491 topic_id: 30186 reply_id: 120947[/import]

Hi there,

I’m curious about the line [lua]timer.cancel(timerInfo);[/lua]. The first time it’s called, [lua]timerInfo[/lua] is an empty table (which is different than [lua]nil[/lua]). I haven’t tested it, but I would not be surprised if passing an empty table to [lua]timer.cancel[/lua] results in the runtime error that you observed. Instead, you should start by declaring [lua]timerInfo[/lua] as [lua]nil[/lua], and then call [lua]timer.cancel[/lua] only if [lua]timerInfo[/lua] is not [lua]nil[/lua].

  • Andrew [import]uid: 109711 topic_id: 30186 reply_id: 120963[/import]

peach pellen: Sorry! Now I notice that the number 507, which I refer to in my previous post, does not match the line that I really mean, but number 507 in this case is equal to 525: timer.cancel(timerInfo);

aukStudios: Unfortunately, I’m not the author of the code, but I have taken over this project and done the best I could to solve the problem. But I will try your suggestion. Thanks! [import]uid: 170055 topic_id: 30186 reply_id: 120976[/import]

Is the above right, that 507 is;
[lua]chatText_txt.x = 0; chatText_txt.y = -15;[/lua] ?

It’s too much code for me to read but as you say about too many bubbles firing too fast, why not use a timer to prevent it firing more than once every X second/s? [import]uid: 52491 topic_id: 30186 reply_id: 120947[/import]

Hi there,

I’m curious about the line [lua]timer.cancel(timerInfo);[/lua]. The first time it’s called, [lua]timerInfo[/lua] is an empty table (which is different than [lua]nil[/lua]). I haven’t tested it, but I would not be surprised if passing an empty table to [lua]timer.cancel[/lua] results in the runtime error that you observed. Instead, you should start by declaring [lua]timerInfo[/lua] as [lua]nil[/lua], and then call [lua]timer.cancel[/lua] only if [lua]timerInfo[/lua] is not [lua]nil[/lua].

  • Andrew [import]uid: 109711 topic_id: 30186 reply_id: 120963[/import]

peach pellen: Sorry! Now I notice that the number 507, which I refer to in my previous post, does not match the line that I really mean, but number 507 in this case is equal to 525: timer.cancel(timerInfo);

aukStudios: Unfortunately, I’m not the author of the code, but I have taken over this project and done the best I could to solve the problem. But I will try your suggestion. Thanks! [import]uid: 170055 topic_id: 30186 reply_id: 120976[/import]