First, I would declare a variable using num1 = NPC.get(274, 0) --Section 0
Then I need to set up a condition using NPC. layerName, NPC.x / NPC.y or whatever I can to locate which Dragon Coins I collected.
Next, I assign a value to another variable.
When the level starts, if the value above changed, I would use num1:kill(9)
I don't know what happens next.
Also, is there a way to check the variable while playing the level using Developer's Console?
Edit: Tried making a variable true after triggered an event. Doesn't work.
Edit after above edit: error attempted to call a method "kill" ( a nil value). Safely assuming I cannot do the first step?
edit after above edit: It finally works as long as 1: I assign a variable to true after the event. 2: Kill use "for k,v in ipairs(NPC.get(274,0)) do v:kill(9)" 3: Re-add the counter
Added in 3 hours 18 minutes 8 seconds:
New codes for every 5-dragon coins levels:vPS: Every dragon coins must in different sections and must trigger an event, no matter what is inside of it
Code: Select all
local counter = 0
SaveData[Level.filename()] = SaveData[Level.filename()] or {}
local levelSD = SaveData[Level.filename()]
function onStart()
player.character=CHARACTER_TOAD
player.powerup=PLAYER_BIG
if levelSD.Coincollected1 then
for k,v in ipairs(NPC.get(274, 0)) do -- the 0 means the section 0
v:kill(9)
counter = counter + 1
(copy above if there is more dragon coins in seperate section, just change the 0 to something else and also the variable name you used)
end
end
end
function onDraw()
Text.print(counter,100 ,100)
end
function onNPCKill(eventObj, killedNPC, killReason)
if killedNPC.id ~= 274 then return end --check if it is a dragon coin
if killReason ~= HARM_TYPE_OFFSCREEN then return end
if Colliders.collide(player, killedNPC) then
. . . . ( IDK what can you put if you have no event to trigger)
counter = counter + 1
end
if counter == 5 then
levelSD.dragonCoinsCollected = true
end
end
function onEvent(eventName)
if eventName == "open" then
levelSD.Coincollected1 = true
(copy above if there is more, change eventname and variable)
end
end