Variables not updating?

This is the place for discussion and support for LunaLua and related modifications and libraries.
Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
IAmPlayer
Volcano Lotus
Volcano Lotus
Posts: 559
Joined: Sun May 21, 2017 3:36 am
Flair: I'm a hellspawn.
Pronouns: he/him
Contact:

Variables not updating?

Postby IAmPlayer » Tue Oct 09, 2018 6:26 am

So, I was coding for my episode in the lunaworld.lua, and it ended up like this.

Code: Select all

API.load("altpsystem")
API.load("nsmbwalls")

--HUD Settings

local hud = Graphics.loadImage(Misc.resolveFile("hud/hud.png"))
local generalReserve = Graphics.loadImage("hardcoded-48-0.png")
local marioReserve = Graphics.loadImage("hardcoded-48-1.png")
local luigiReserve = Graphics.loadImage("hardcoded-48-2.png")
local coinCounter = 0;

function onTick()
    Graphics.activateHud(false)
	Graphics.drawImageWP(hud, 0, 0, 5)
	--Life Counter of the HUD
	Text.printWP(mem(0x00B2C5AC,FIELD_FLOAT), 106, 14, 5)
	--Star Counter of the HUD
	Text.printWP(mem(0x00B251E0,FIELD_WORD), 298, 14, 5)
	--Score Counter of the HUD
	Text.printWP(mem(0x00B2C8E4,FIELD_DWORD), 634, 20, 5)
	--Coin Counter of the HUD
	Text.printWP(coinCounter, 516, 14, 5)
end

--How to count the Coins
function onNPCKill(eventObj,killedNPC,killReason)
    if npcID == 10 then
	    coinCounter = coinCounter + 1;
	end
	if npcID == 103 then
	    coinCounter = coinCounter + 1;
	end
	if npcID == 258 then
	    coinCounter = coinCounter + 5;
	end
	if npcID == 274 then
	    coinCounter = coinCounter + 20;
	end
end
Once I tried it out, the variable CoinCounter doesn't update everytime I collected a coin. Anyone knows what happened?

PixelPest
Raccoon Mario
Raccoon Mario
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Variables not updating?

Postby PixelPest » Tue Oct 09, 2018 7:16 am

Responded on Discord but I'll add it here for good measure. You've never defined npcID as a variable anywhere in your code. If you change it to killedNPC.id it should work


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari