changing gameplay through different values

Hey guys, basically I have a variable called ‘Size’ which holds values in increments of 1. 

What Im trying to do is to change a weight velocity of the character dependant on the value held in the size variable. 

Here is what I have: 

local size = 1

And the set up for the player flying function.

function activateFly(event) ship:applyForce(0, -2.5, ship.x, ship.y) end

What I intend to do is something like this (code below is just an example)

function activateFly(event) if 'size' == 1 then ship:applyForce(0, -2.5, ship.x, ship.y) elseif 'size' == 2 then ship:applyForce(0, -0.5, ship.x, ship.y) end end

this is the function which calls the activateFly function

function touchScreen(event) print("touch") if event.phase == "began" then ship.enterFrame = activateFly Runtime:addEventListener("enterFrame", ship) end if event.phase == "ended" then Runtime:removeEventListener("enterFrame", ship) end end

Thanks in advance. 

Hi @dip,

And how is this working at the current time? I suggest you put a “return true” at the end of your touch handler. Otherwise, there doesn’t appear to be anything out of place. :slight_smile:

Take care,

Brent

Hi Brent Sorrentino, Thanks for the reply. At the moment, with the current setup show above, the game loses its touch functionality completely. I used a print command to check whether the touch was registering, which it was, but saw it was not using the Fly function at all, meaning it just drops off screen. I added the ‘return true’ before closing of the touch handler and it still does not work. 

Is there another way, or setup which would make this work?

Just an update the code is now working fine after using return true. However i want to ask if there is a way in which i could set up the code so that for each value of 1 thats collected, it increases the force amount of the player (weight) 

At the moment when the size reaches the last ELSEIF code it just stops, meaning that i would need to write up more ELSEIF statements to keep it going on. 

Sorry if this sounds confusing. Ive looked around on google and couldnt find anything. 

In this case, I suggest you just use the “size” number, divide it by something, and use the result to apply a calculated force. This would save you from writing dozens of "elseif"s for every single size possibility.

Hi Brent, Thanks for the help. How would I set that up so that it works? Would it be possible if you could show me an example of how it would look in code?

Hi @dip,

And how is this working at the current time? I suggest you put a “return true” at the end of your touch handler. Otherwise, there doesn’t appear to be anything out of place. :slight_smile:

Take care,

Brent

Hi Brent Sorrentino, Thanks for the reply. At the moment, with the current setup show above, the game loses its touch functionality completely. I used a print command to check whether the touch was registering, which it was, but saw it was not using the Fly function at all, meaning it just drops off screen. I added the ‘return true’ before closing of the touch handler and it still does not work. 

Is there another way, or setup which would make this work?

Just an update the code is now working fine after using return true. However i want to ask if there is a way in which i could set up the code so that for each value of 1 thats collected, it increases the force amount of the player (weight) 

At the moment when the size reaches the last ELSEIF code it just stops, meaning that i would need to write up more ELSEIF statements to keep it going on. 

Sorry if this sounds confusing. Ive looked around on google and couldnt find anything. 

In this case, I suggest you just use the “size” number, divide it by something, and use the result to apply a calculated force. This would save you from writing dozens of "elseif"s for every single size possibility.

Hi Brent, Thanks for the help. How would I set that up so that it works? Would it be possible if you could show me an example of how it would look in code?