In this app I'm creating with Corona SDK, when you win the text "You win" sould appear, but doesn't. I could post all the code, but I don't think the rest would be hepful, so here is only the essencial:
_H = display.contentHeight;
_W = display.contentWidth;
mRand = math.random;
o = 0;
time_remain = 20;
time_up = false;
total_orbs = 45;
total_secs = 20;
ready = false;
local backGround = display.newImage("media/bg.png");
backGround.xScale = 2;
backGround.yScale = 2;
loseMSG = display.newText("You Lose!", _W/2, _H/2, nil, 50)
loseMSG.isVisible = false
winMSG = display.newText("You Win!", _W/2, _H/2, nil, 50)
winMSG.isVisible = false
local countdowntxt = display.newText(time_remain, 0, 0, native.systemFont, 60);
countdowntxt.xScale = .5; countdowntxt.yScale = .5;
countdowntxt:setReferencePoint(display.BottomRightReferencePoint);
countdowntxt.x = _W-20; display.y = _H-20;
countdowntxt:setTextColor(0, 0, 0)
function winLose(condition)
if (condition == "Win") then
bgAlpha = display.newImage("media/bgAlpha.png");
bgAlpha.xScale = 2;
bgAlpha.yScale = 2;
winMSG.isVisible = true -- Here the win text should become visible, but doesn't
elseif (condition == "Fail") then
bgAlpha = display.newImage("media/bgAlpha.png");
bgAlpha.xScale = 2;
bgAlpha.yScale = 2;
loseMSG.isVisible = true
end
end
Any Ideas why?
You need to take a divide and conquer approach.
Does this work?
winMSG = display.newText("You Win!", _W/2, _H/2, nil, 50)
winMSG.isVisible = true <-- note this is set to true
It does?
Does winLose every get called? Put a print statement in it or a break point or whatever you use on your platform to debug.
It does?
What does the variable condition contain? Inspect it/print it out and verify that it is indeed "Win", same case, no spaces, etc. or you can put a print statement in the appropriate branch of that function to make sure it's being hit.
Is that OK?
Does it show up if you remove the bgAlpha code?
So on and so forth.
I don't know Corona, but Googling the docs for newText it's possible you have the parameters wrong (you're not passing a font).
I could post all the code
The less you post the better, because that means you've already gone through the steps shown above to try to isolate the problem. Nine times out of ten, doing that will reveal the problem all by itself.
Why have you given nil for font value?
Atleast pass the default system font
loseMSG = display.newText("You Lose!", _W/2, _H/2, native.systemFont, 50)
winMSG = display.newText("You Win!", _W/2, _H/2, native.systemFont, 50)
Related
So, this is my problem.
This script works with one image id, but not any others.
I literally have no idea why this is happening.
This is the script >>
function newEntity(imgId, eName)
EntityBase = Instance.new("Part", workspace)
EntityBase.Transparency = 1
EntityBase.Size = Vector3.new(0.9, 0.1, 0.7)
EntityBase.Name = eName
EntityBillboardGui = Instance.new("BillboardGui", EntityBase)
EntityBillboardGui.StudsOffset = Vector3.new(0, 5, 0)
EntityBillboardGui.Size = UDim2.new(0,250,0,250)
EntityBillboardGui.MaxDistance = math.huge
EntityBillboardGui.Adornee = EntityBase
EntityImage = Instance.new("ImageLabel",EntityBillboardGui)
EntityImage.Size = EntityBillboardGui.Size
EntityImage.BackgroundTransparency = 1
EntityImage.Image = imgId
return EntityBase
end
troller = newEntity("rbxthumb://11954446780","imposter")
troller.Position = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
trololol = Instance.new("Sound", troller)
trololol.SoundId = "http://www.roblox.com/asset/?id=5677788502"
trololol:Play()
wait(2)
troller:Destroy()
game.Players.LocalPlayer.Character.Humanoid.Health = 0
Can anybody help fix it?
For starters I would recommend seperating the parent, like this:
EntityBase = Instance.new("Part") EntityBase.Parent = workspace
SECOND: I would recommend not using a seperate part, just put the billboardGui into the player's head
third you used rbxthumb wrong
rbxthumb://type=[ThumbnailType]&id=[TargetId]&w=[Width]&h=[Height]”
These are the supported sizes and types
example: rbxthumb://type=Avatar&id=123456789&w=720&h=720
I've searched everywhere for an answer on how to change a variable inside a function. I have tried many different solutions but none have worked so far.
My plan is to change a variable named 'stateRed' inside a function which is run when a button is pressed. When the function is run, the variables will change to 'READY'. I will then use this variable to run a separate chunk of code (the actual game). There are two of these buttons.
My code looks something like this:
function ReadyRed()
stateRed = 'READY'
stateBtnRed = widget.newButton
{
defaultFile = "ready_red.png",
overFile = "unready_red.png",
label = "Ready",
emboss = true,
onPress = unreadyStateRed,
}
stateBtnRed.rotation = 90; stateBtnRed.width = 90; stateBtnRed.height = 90; stateBtnRed.x = display.contentWidth / 2 - 170; stateBtnRed.y = display.contentHeight - 270
return stateRed
end
function UnreadyRed()
local stateRed = 'UNREADY'
stateBtnRed = widget.newButton
{
defaultFile = "unready_red.png",
overFile = "ready_red.png",
label = "Unready",
emboss = true,
onPress = readyStateRed,
}
stateBtnRed.rotation = 90; stateBtnRed.width = 90; stateBtnRed.height = 90; stateBtnRed.x = display.contentWidth / 2 - 170; stateBtnRed.y = display.contentHeight - 270
return stateRed
end
The code that starts the game looks like this:
if stateRed == 'READY' and stateBlue == 'Ready' then
If variable stateRed is global then remove local keyword stand before variable name i.e.
function UnreadyRed()
stateRed = 'UNREADY'
...
end
Note:
You probably don't need return stateRed in ReadyRed and UnreadyRed functions since stateRed is global variable.
Use one notation style. I recommended you Camel Case notation
I am geeting an error: main.lua:25:attempt to call method'setanchorPoint'(a nil value)stack traceback:main.lua25:in maiin chunk. Please tell me how can I use anchorPoint. And how to resolve this issue
--constants
_H = display.contentHeight;
_W = display.contentWidth;
mRand = math.random;
o = 0;
time_remain = 10;
time_up = false;
total_orbs = 20;
ready = false;
--Prepare sounds to be played or accessed
local soundtrack = audio.loadStream("media/soundtrack.caf");
local pop_sound = audio.loadSound("media/pop.caf");
local win_sound = audio.loadSound("media/win.caf");
local fail_sound = audio.loadSound("media/fail.caf");
local display_txt = display.newText("Wait", 0, 0, native.systemFont, 16*2);
display_txt.xScale = .5; display_txt.yScale = .5;
display_txt:setanchorPoint(display.BottomLeftanchorPoint);
display_txt.x = 20; display_txt.y = _H-20;
If you want to know how to use anchor points in Corona, the usual approach is to refer to the Corona manual....
Corona Anchor Guide
Anchors
The anchor of an object controls how geometry is positioned
relative to the object's origin. This is specified via the
object.anchorX and object.anchorY properties.
They even give examples....
You cannot just invent function names and wonder why you get error messages for callinig them.
I get the following error message from Corona SDK : attempt to call field "ImageSheet" (a nil value) stack traceback. Can somebody point out the mistake?
local ISPar = {
width = 2541,
height = 264,
numFrames = 7
}
local ImageSheet = graphics.ImageSheet("Apus.png, ISPar")
local ApusSequenceData = {
{name = "fly", frames {1,2,3,4,5,6,7}, time = 800, loopCount = 0}
}
local Apus = display.newSrpite(ImageSheet, ApusSequenceData)
Apus.x = display.contentWidth/2
Apus.y = display.contentHeight/2
Apus:play()
You got the function name wrong, it was supposed to be graphics.newImageSheet. Also you misplaced the quotation marks when calling it. And afterwards you misspelt newSprite
This code should work:
local ISPar = {
width = 2541,
height = 264,
numFrames = 7
}
local ImageSheet = graphics.newImageSheet("Apus.png", ISPar)
local ApusSequenceData = {{name = "fly", frames = {1,2,3,4,5,6,7}, time = 800, loopCount = 0}}
local Apus = display.newSprite(ImageSheet, ApusSequenceData)
Apus.x = display.contentWidth/2
Apus.y = display.contentHeight/2
Apus:play()
I have two questions. what I am
trying to do is every time I shoot a enemy/vine it should be
removed and a explosion should occur. the removal works perfect
but the sprite is not called to explode
What's this in the for loop #sections[sectInt]["vines"] ?
Are they parent/ child references? Can someone break this
down to the letter even telling me what the # is?
How can I use my explosion sprite after each vine is destroyed?
I am having a difficult time figuring out how to call every x and y
vine in the for loop to explode when removed.
Code:
local sections = require("sectionData")
local lastSection = 0
function createSection()
--Create a random number. If its eqaul to the last one, random it again.
local sectInt = mR(1,#sections)
if sectInt == lastSection then sectInt = mR(1,#sections) end
lastSection = sectInt
--Get a random section from the sectionData file and then
--Loop through creating everything with the right properties.
local i
-- the random creation of vines throughout the screen
for i=1, #sections[sectInt]["vines"] do
local object = sections[sectInt]["vines"][i]
local vine = display.newImageRect(objectGroup, "images/vine"..object["type"]..".png", object["widthHeight"][1], object["widthHeight"][2])
vine.x = object["position"][1]+(480*object["screen"]); vine.y = object["position"][2]; vine.name = "vine"
local rad = (vine.width*0.5)-8; local height = (vine.height*0.5)-8
local physicsShape = { -rad, -height, rad, -height, rad, height, -rad, height }
physics.addBody( vine, "static", { isSensor = true, shape = physicsShape } )
end
end
-- explosion sprite
options1 =
{
width = 96, height = 96,
numFrames = 16,
sheetContentWidth = 480,
sheetContentHeight = 384
}
playerSheet1 = graphics.newImageSheet( "images/explosion.png", options1)
playerSprite1 = {
{name="explosion", start=1, count=16, time = 400, loopCount = 1 },
}
explode = display.newSprite(playerSheet1, playerSprite1)
explode.anchorX = 0.5
explode.anchorY = 1
--player:setReferencePoint(display.BottomCenterReferencePoint)
-- i want to reference the for loop position if each vine so it plays sprite when they are removed
explode.x = "vine.x" ; explode.y = "vine .y"
explode.name = "explode"
explode.position=1
extraGroup:insert(explode)
1) What's this in the for loop #sections[sectInt]["vines"] ? Are they parent/ child references? Can someone break this down to the letter even telling me what the # is?
As I said in my comment the # is table length.
The loop is looping over each bit of "vine" data in the selected segment data (whatever that means exactly in terms of the game) and then creates the objects for those vines.
When it's time to make your vine explode, you play the sprite. If you want to explode every vine, you would have something like:
sheetOptions =
{
width = 96, height = 96,
numFrames = 16,
sheetContentWidth = 480,
sheetContentHeight = 384
}
playerSheet = graphics.newImageSheet( "images/explosion.png", sheetOptions)
spriteSequence = {
{name="explosion", start=1, count=16, time = 400, loopCount = 1 },
}
for i, vine in ipairs(objectGroup) do
local explode = display.newSprite(playerSheet, spriteSequence)
explode.anchorX = 0.5
explode.anchorY = 1
explode.x = vine.x
explode.y = vine.y
explode.name = "explode"
explode.position=1
explode:play()
extraGroup:insert(explode)
end
Note: not tested, let me know of if any issues you can't resolve.
ok so, this is what i did to get my object to have a explosion, for anybody that is having the same issue.
function isShot( event )
print('shot!!!')
if (event.other.class == "enemy") then
if (event.other.name == "limitLine") then
event.target:doRemove() --remove bullet if hits the limitLine
elseif (event.other.name == "vine") then
event.other:doRemove()
spriteExplode(event.other.x, event.other.y) -- this function calls itself & runs the sprite
if event.other.name == "vine" then
if event.other.name == "explode" then
event.other:doRemove() --this removes the explosion sprite
end
end
end
-- remove the bullet & explosion sprite
timer.performWithDelay( 5000, function(event) explode:doRemove(); end, 1 )
event.target:doRemove()
end
return true
end
function spriteExplode( x, y)
explode.isVisible = true
explode:play()
print("play explode")
if (x and y) then -- this is the code that keeps my sprite updating upon removal of vine
explode.x, explode.y = x, y
end
function explode:doRemove(event)
timer.performWithDelay(
1,
function(event)
display.remove(self)
self= nil
end,
1 )
end
end
i added the isShot function eventListener inside of the Bullet function
bullet:addEventListener("collision", isShot) & a bullet:doRemove function is inside the bullet function as well.
hope this helps.