(Help) Data Set Value Reverting to 0

This is the place for discussion and support for LunaLua and related modifications and libraries.

Moderator: Userbase Moderators

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?
LM280
Monty Mole
Monty Mole
Posts: 121
Joined: Wed Jan 15, 2014 7:10 pm

(Help) Data Set Value Reverting to 0

Postby LM280 » Sat Jun 03, 2017 12:10 am

Okay, so this is kind of hard to explain, but basically in my project, Super Mario-Troid, I have 3 data sets that store what items the player has gotten so far. I only want them to keep the item if they reach a save door without dying, so when grabbing the item, it sets the value (default 0) to 1, and then when the door animation plays it sets any 1 values to 2. If the player dies, any 1 values are reset to 0. This works perfectly, except for one item, the Spinjump Boots. The purpose is to regain the spinjump ability you lose at the beginning of the game. They function fine, but unlike every other item in the game, when you save and re enter the level, the value reverts back to 0 and you lose the upgrade. Even more strangely, when I went back and grabbed the item again and saved, I DID keep the item. (I tested this multiple times. You have to get the item, save, and get it again for it to stick.) I've combed through the code over and over but I can't figure out what's wrong. I set the Inventory:get("Spinjump Boots") value to display on the screen and I saw it change to 1 and then to 2 when I entered the door, but upon re entering it was 0 again.

Here's the code from lunaworld.lua:
Spoiler: show

Code: Select all

local encrypt = API.load("encrypt");
_G["Inventory"] = encrypt.Data(Data.DATA_WORLD, "Super Mario-Troid", true)
_G["Progress"] = encrypt.Data(Data.DATA_WORLD, "Super Mario-Troid", true)
_G["Bonus"] = encrypt.Data(Data.DATA_WORLD, "Super Mario-Troid", true)

local rng = API.load("rng");
local smallStart = Graphics.loadImage("mario-1start.gif")
local smallSpinJump = Graphics.loadImage("mario-1spinjump.gif")
local smallGravity = Graphics.loadImage("mario-1gravity.gif")
local smallVaria = Graphics.loadImage("mario-1varia.gif")
local smallHiJump = Graphics.loadImage("mario-1hijump.gif")
local smallSpaceJump = Graphics.loadImage("mario-1spacejump.gif")
local smallCos1 = Graphics.loadImage("mario-1wa.gif")
local smallCos2 = Graphics.loadImage("mario-1grand.gif")
local smallCos3 = Graphics.loadImage("mario-1samus.gif")
local superSpinJump = Graphics.loadImage("mario-2spinjump.gif")
local superGravity = Graphics.loadImage("mario-2gravity.gif")
local superVaria = Graphics.loadImage("mario-2varia.gif")
local superHiJump = Graphics.loadImage("mario-2hijump.gif")
local superSpaceJump = Graphics.loadImage("mario-2spacejump.gif")
local superCos1 = Graphics.loadImage("mario-2wa.gif")
local superCos2 = Graphics.loadImage("mario-2grand.gif")
local superCos3 = Graphics.loadImage("mario-2samus.gif")
local fireSpinJump = Graphics.loadImage("mario-3spinjump.gif")
local fireGravity = Graphics.loadImage("mario-3gravity.gif")
local fireVaria = Graphics.loadImage("mario-3varia.gif")
local fireHiJump = Graphics.loadImage("mario-3hijump.gif")
local fireSpaceJump = Graphics.loadImage("mario-3spacejump.gif")
local fireCos1 = Graphics.loadImage("mario-3wa.gif")
local fireCos2 = Graphics.loadImage("mario-3grand.gif")
local fireCos3 = Graphics.loadImage("mario-3samus.gif")
local raccoonGravity = Graphics.loadImage("mario-4gravity.gif")
local raccoonVaria = Graphics.loadImage("mario-4varia.gif")
local raccoonHiJump = Graphics.loadImage("mario-4hijump.gif")
local raccoonSpaceJump = Graphics.loadImage("mario-4spacejump.gif")
local raccoonCos1 = Graphics.loadImage("mario-4wa.gif")
local raccoonCos2 = Graphics.loadImage("mario-4grand.gif")
local raccoonCos3 = Graphics.loadImage("mario-4samus.gif")
local tanookiCos1 = Graphics.loadImage("mario-5wa.gif")
local tanookiCos2 = Graphics.loadImage("mario-5grand.gif")
local tanookiCos3 = Graphics.loadImage("mario-5samus.gif")
local hammerHiJump = Graphics.loadImage("mario-6hijump.gif")
local hammerSpaceJump = Graphics.loadImage("mario-6spacejump.gif")
local hammerCos1 = Graphics.loadImage("mario-6wa.gif")
local hammerCos2 = Graphics.loadImage("mario-6grand.gif")
local hammerCos3 = Graphics.loadImage("mario-6samus.gif")
local iceGravity = Graphics.loadImage("mario-7gravity.gif")
local iceVaria = Graphics.loadImage("mario-7varia.gif")
local iceHiJump = Graphics.loadImage("mario-7hijump.gif")
local iceSpaceJump = Graphics.loadImage("mario-7spacejump.gif")
local iceCos1 = Graphics.loadImage("mario-7wa.gif")
local iceCos2 = Graphics.loadImage("mario-7grand.gif")
local iceCos3 = Graphics.loadImage("mario-7samus.gif")
local newRecover = 0

function initialize()
	if Inventory:get("Jump Boots") == nil then
		Inventory:set("Jump Boots", 0)
	end
	if Inventory:get("Spinjump Boots") == nil then
		Inventory:set("Spinjump Boots", 0)
	end
	if Inventory:get("Gravity Cap") == nil then
		Inventory:set("Gravity Cap", 0)
	end
	if Inventory:get("Varia Cap") == nil then
		Inventory:set("Varia Cap", 0)
	end
	if Inventory:get("Hi-Jump Boots") == nil then
		Inventory:set("Hi-Jump Boots", 0)
	end
	if Inventory:get("Space Jump Boots") == nil then
		Inventory:set("Space Jump Boots", 0)
	end
	Inventory:save()
	if Progress:get("Shygon Switcher") == nil then
		Progress:set("Shygon Switcher", 0)
	end
	if Progress:get("Shygon Boss") == nil then
		Progress:set("Shygon Boss", 0)
	end
	if Progress:get("Mushroom") == nil then
		Progress:set("Mushroom", 0)
	end
	if Progress:get("Koopteria Bricks") == nil then
		Progress:set("Koopteria Bricks", 0)
	end
	if Progress:get("Koopteria Key") == nil then
		Progress:set("Koopteria Key", 0)
	end
	if Progress:get("Fire Flower") == nil then
		Progress:set("Fire Flower", 0)
	end
	if Progress:get("Phenpiranha Ice") == nil then
		Progress:set("Phenpiranha Ice", 0)
	end
	if Progress:get("Koopteria Brick Wall") == nil then
		Progress:set("Koopteria Brick Wall", 0)
	end
	if Progress:get("Super Leaf") == nil then
		Progress:set("Super Leaf", 0)
	end
	if Progress:get("Ice Flower") == nil then
		Progress:set("Ice Flower", 0)
	end
	if Progress:get("Bob-Bryyo Key") == nil then
		Progress:set("Bob-Bryyo Key", 0)
	end
	if Progress:get("Bob-Bryyo Maze") == nil then
		Progress:set("Bob-Bryyo Maze", 0)
	end
	if Progress:get("Mines Key") == nil then
		Progress:set("Mines Key", 0)
	end
	Progress:save()
	if Bonus:get("Speed Booster") == nil then
		Bonus:set("Speed Booster", 0)
	end
	if Bonus:get("Recover Up") == nil then
		Bonus:set("Recover Up", 0)
	end
	if Bonus:get("Flamethrower") == nil then
		Bonus:set("Flamethrower", 0)
	end
	if Bonus:get("Costume1") == nil then
		Bonus:set("Costume1", 0)
	end
	if Bonus:get("Costume2") == nil then
		Bonus:set("Costume2", 0)
	end
	if Bonus:get("Costume3") == nil then
		Bonus:set("Costume3", 0)
	end
	Bonus:save()
end

function onStart()
   initialize()
   progressCheck()
end

function onEvent(eventname)
	if eventname == "Jump Boots" then
		Inventory:set("Jump Boots", 1)
		Inventory:save()
		playerGraphics()
	end
	if eventname == "Spinjump Boots" then
		Inventory:set("Spinjump Boots", 1)
		Inventory:save()
		playerGraphics()
	end
	if eventname == "Gravity Cap" then
		Inventory:set("Gravity Cap", 1)
		Inventory:save()
		playerGraphics()
	end
	if eventname == "Varia Cap" then
		Inventory:set("Varia Cap", 1)
		Inventory:save()
		playerGraphics()
	end
	if eventname == "Hi-Jump Boots" then
		Inventory:set("Hi-Jump Boots", 1)
		Inventory:save()
		playerGraphics()
	end
	if eventname == "Space Jump Boots" then
		Inventory:set("Space Jump Boots", 1)
		Inventory:save()
		playerGraphics()
	end
	if eventname == "Frigate Start" then
		Inventory:set("Jump Boots", 2)
		Inventory:set("Spinjump Boots", 2)
		Inventory:set("Gravity Cap", 2)
		Progress:set("Mushroom", 2)
		Progress:save()
		Inventory:save()
		playerGraphics()
	end
	if eventname == "Lose Items" then
		Inventory:set("Jump Boots", 0)
		Inventory:set("Spinjump Boots", 0)
		Inventory:set("Gravity Cap", 0)
		Progress:set("Mushroom", 0)
		Progress:save()
		Inventory:save()
		player.powerup = PLAYER_SMALL;
		player.reservePowerup = 0;
	end
	if eventname == "Speed Booster" then
		if Bonus:get("Speed Booster") == 0 then
			Bonus:set("Speed Booster", 1)
		else
			Bonus:set("Speed Booster", 0)
		end
		Bonus:save()
	end
	if eventname == "Recover Up" then
		if Bonus:get("Recover Up") == 0 then
			Bonus:set("Recover Up", 1)
		else
			Bonus:set("Recover Up", 0)
		end
		Bonus:save()
	end
	if eventname == "Flamethrower" then
		if Bonus:get("Flamethrower") == 0 then
			Bonus:set("Flamethrower", 1)
		else
			Bonus:set("Flamethrower", 0)
		end
		Bonus:save()
	end
	if eventname == "Costume1" then
		if Bonus:get("Costume1") == 0 then
			Bonus:set("Costume1", 1)
		else
			Bonus:set("Costume1", 0)
			
		end
		Bonus:set("Costume2", 0)
		Bonus:set("Costume3", 0)
		Bonus:save()
		playerGraphics()
	end
	if eventname == "Costume2" then
		if Bonus:get("Costume2") == 0 then
			Bonus:set("Costume2", 1)
		else
			Bonus:set("Costume2", 0)
		end
		Bonus:set("Costume1", 0)
		Bonus:set("Costume3", 0)
		Bonus:save()
		playerGraphics()
	end
	if eventname == "Costume3" then
		if Bonus:get("Costume3") == 0 then
			Bonus:set("Costume3", 1)
		else
			Bonus:set("Costume3", 0)
		end
		Bonus:set("Costume1", 0)
		Bonus:set("Costume2", 0)
		Bonus:save()
		playerGraphics()
	end
	if eventname == "Shygon Switcher" then
		if Progress:get("Shygon Switcher") == 0 then
			Progress:set("Shygon Switcher", 1)
			Progress:save()
		elseif Progress:get("Shygon Switcher") == 1 then
			Progress:set("Shygon Switcher", 0)
			Progress:save()
		elseif Progress:get("Shygon Switcher") == 2 then
			Progress:set("Shygon Switcher", 3)
			Progress:save()
		elseif Progress:get("Shygon Switcher") == 3 then
			Progress:set("Shygon Switcher", 2)
			Progress:save()
		end
	end
	if eventname == "Shygon Boss Start" then
		playSFX("ShyGuy.wav")
	end
	if eventname == "Shygon Boss" then
		Progress:set("Shygon Boss", 1)
		Progress:save()
	end
	if eventname == "Mushroom" then
		Progress:set("Mushroom", 1)
		Progress:save()
	end
	if eventname == "Koopteria Bricks" then
		Progress:set("Koopteria Bricks", 1)
		Progress:save()
	end
	if eventname == "Koopteria Key" then
		Progress:set("Koopteria Key", 1)
		Progress:save()
	end
	if eventname == "Fire Flower" then
		Progress:set("Fire Flower", 1)
		Progress:save()
	end
	if eventname == "Phenpiranha Ice" then
		Progress:set("Phenpiranha Ice", 1)
		Progress:save()
	end
	if eventname == "Koopteria Brick Wall" then
		Progress:set("Koopteria Brick Wall", 1)
		Progress:save()
	end
	if eventname == "Super Leaf" then
		Progress:set("Super Leaf", 1)
		Progress:save()
	end
	if eventname == "Item SFX" then
		playSFX("Item.wav")
	end
	if eventname == "Ice Flower" then
		Progress:set("Ice Flower", 1)
		Progress:save()
	end
	if eventname == "Bob-Bryyo Key" then
		Progress:set("Bob-Bryyo Key", 1)
		Progress:save()
	end
	if eventname == "Bob-Bryyo Maze" then
		Progress:set("Bob-Bryyo Maze", 1)
		Progress:save()
	end
	if eventname == "Mines Key" then
		Progress:set("Mines Key", 1)
		Progress:save()
	end
end
   
function onInputUpdate()
	if Inventory:get("Jump Boots") == 0 then
		if player.jumpKeyPressing == true then
			player.jumpKeyPressing = false
		end
	end
	if Inventory:get("Spinjump Boots") == 0 then
		if Inventory:get("Jump Boots") == 0 then
			if player.altJumpKeyPressing == true then
				player.altJumpKeyPressing = false
			end
		elseif Inventory:get("Jump Boots") > 0 then
			if player.altJumpKeyPressing == true then
				player.altJumpKeyPressing = false
				player.jumpKeyPressing = true
			end
		end
	end
	if Inventory:get("Hi-Jump Boots") > 0 then
		if Inventory:get("Space Jump Boots") == 0 then
			if player.jumpKeyPressing == true then
				if player:mem(0x146, FIELD_WORD) == 1 then
					player:mem(0x11C,FIELD_WORD,50)
				end
			end
		end
	end
end

function onKeyDown(keycode)
if Inventory:get("Space Jump Boots") > 0 then
	if player:mem(0x34, FIELD_WORD) == 0 then
		if player:mem(0x122, FIELD_WORD) == 0 then
			if keycode == KEY_JUMP then
				player.speedY = -11;
				if player:mem(0x146,FIELD_WORD) == 0 then
					playSFX(1)
					for i=-3,3,6 do
						local smoke = Animation.spawn(74,player.x+(player.width/2),player.y)
						smoke.speedX = i;
						smoke.speedY = 4;
						end
					end
				end
			end
		end
	end
end

function onTick()
	if Inventory:get("Gravity Cap") == 0 then
		player:mem(0x38, FIELD_WORD, -1)
	end
	if player:mem(0x13E, FIELD_WORD) > 0 then
		playerDeath()
	end
	if player:mem(0x122, FIELD_WORD) == 7 then
		gameSave()
	end
	stars = NPC.get(196, -1)
    if(table.getn(stars) > 0) then
        for i=1,table.getn(stars) do
            stars[i]:mem(0xA0, FIELD_DFLOAT, 0)
			stars[i]:mem(0x108, FIELD_DFLOAT, 0)
        end
    end
	if Bonus:get("Speed Booster") == 1 then
		Defines.player_runspeed = 8
		if player.speedX >= 6 then
			player:mem(0x16C, FIELD_WORD, 1)
		end
		if player.speedX <= -6 then
			player:mem(0x16C, FIELD_WORD, 1)
		end
	end
	if Bonus:get("Speed Booster") == 0 then
		Defines.player_runspeed = 6
	end
	if Bonus:get("Recover Up") == 1 then
		if player:mem(0x140, FIELD_WORD) == 150 then
			newRecover = 300
			player:mem(0x140, FIELD_WORD, 2)
		end
		if newRecover > 0 then
			newRecover = newRecover - 1
			player:mem(0x140, FIELD_WORD, 1)
		end
	end
	if Bonus:get("Flamethrower") == 1 then
		Defines.cheat_flamerthrower = true
	end
	if Bonus:get("Flamethrower") == 0 then
		Defines.cheat_flamerthrower = false
	end
end

function playerDeath()
	player.reservePowerup = 0;
	if Inventory:get("Jump Boots") == 1 then
		Inventory:set("Jump Boots", 0)
		Inventory:save()
	end
	if Inventory:get("Spinjump Boots") == 1 then
		Inventory:set("Spinjump Boots", 0)
		Inventory:save()
	end
	if Inventory:get("Gravity Cap") == 1 then
		Inventory:set("Gravity Cap", 0)
		Inventory:save()
	end
	if Inventory:get("Varia Cap") == 1 then
		Inventory:set("Varia Cap", 0)
		Inventory:save()
	end
	if Inventory:get("Hi-Jump Boots") == 1 then
		Inventory:set("Hi-Jump Boots", 0)
		Inventory:save()
	end
	if Inventory:get("Space Jump Boots") == 1 then
		Inventory:set("Space Jump Boots", 0)
		Inventory:save()
	end
	if Progress:get("Shygon Switcher") == 1 then
		Progress:set("Shygon Switcher", 0)
		Progress:save()
	end
	if Progress:get("Shygon Switcher") == 3 then
		Progress:set("Shygon Switcher", 2)
		Progress:save()
	end
	if Progress:get("Shygon Boss") == 1 then
		Progress:set("Shygon Boss", 0)
		Progress:save()
	end
	if Progress:get("Mushroom") == 1 then
		Progress:set("Mushroom", 0)
		Progress:save()
	end
	if Progress:get("Koopteria Bricks") == 1 then
		Progress:set("Koopteria Bricks", 0)
		Progress:save()
	end
	if Progress:get("Koopteria Key") == 1 then
		Progress:set("Koopteria Key", 0)
		Progress:save()
	end
	if Progress:get("Fire Flower") == 1 then
		Progress:set("Fire Flower", 0)
		Progress:save()
	end
	if Progress:get("Phenpiranha Ice") == 1 then
		Progress:set("Phenpiranha Ice", 0)
		Progress:save()
	end
	if Progress:get("Koopteria Brick Wall") == 1 then
		Progress:set("Koopteria Brick Wall", 0)
		Progress:save()
	end
	if Progress:get("Super Leaf") == 1 then
		Progress:set("Super Leaf", 0)
		Progress:save()
	end
	if Progress:get("Ice Flower") == 1 then
		Progress:set("Ice Flower", 0)
		Progress:save()
	end
	if Progress:get("Bob-Bryyo Key") == 1 then	
		Progress:set("Bob-Bryyo Key", 0)
		Progress:save()
	end
	if Progress:get("Bob-Bryyo Maze") == 1 then
		Progress:set("Bob-Bryyo Maze", 0)
		Progress:save()
	end
	if Progress:get("Mines Key") == 1 then
		Progress:set("Mines Key", 0)
		Progress:save()
	end
end

function gameSave()
if Inventory:get("Jump Boots") == 1 then
		Inventory:set("Jump Boots", 2)
		Inventory:save()
	end
	if Inventory:get("Spinjump Boots") == 1 then
		Inventory:set("Spinjump Boots", 2)
		Inventory:save()
	end
	if Inventory:get("Gravity Cap") == 1 then
		Inventory:set("Gravity Cap", 2)
		Inventory:save()
	end
	if Inventory:get("Varia Cap") == 1 then
		Inventory:set("Varia Cap", 2)
		Inventory:save()
	end
	if Inventory:get("Hi-Jump Boots") == 1 then
		Inventory:set("Hi-Jump Boots", 2)
		Inventory:save()
	end
	if Inventory:get("Space Jump Boots") == 1 then
		Inventory:set("Space Jump Boots", 2)
		Inventory:save()
	end
	if Progress:get("Shygon Switcher") == 1 then
		Progress:set("Shygon Switcher", 2)
		Progress:save()
	end
	if Progress:get("Shygon Switcher") == 3 then
		Progress:set("Shygon Switcher", 0)
		Progress:save()
	end
	if Progress:get("Shygon Boss") == 1 then
		Progress:set("Shygon Boss", 2)
		Progress:save()
	end
	if Progress:get("Mushroom") == 1 then
		Progress:set("Mushroom", 2)
		Progress:save()
	end
	if Progress:get("Koopteria Bricks") == 1 then
		Progress:set("Koopteria Bricks", 2)
		Progress:save()
	end
	if Progress:get("Koopteria Key") == 1 then
		Progress:set("Koopteria Key", 2)
		Progress:save()
	end
	if Progress:get("Fire Flower") == 1 then
		Progress:set("Fire Flower", 2)
		Progress:save()
	end
	if Progress:get("Phenpiranha Ice") == 1 then
		Progress:set("Phenpiranha Ice", 2)
		Progress:save()
	end
	if Progress:get("Koopteria Brick Wall") == 1 then
		Progress:set("Koopteria Brick Wall", 2)
		Progress:save()
	end
	if Progress:get("Super Leaf") == 1 then
		Progress:set("Super Leaf", 2)
		Progress:save()
	end
	if Progress:get("Ice Flower") == 1 then
		Progress:set("Ice Flower", 2)
		Progress:save()
	end
	if Progress:get("Bob-Bryyo Key") == 1 then
		Progress:set("Bob-Bryyo Key", 2)
		Progress:save()
	end
	if Progress:get("Bob-Bryyo Maze") == 1 then
		Progress:set("Bob-Bryyo Maze", 2)
		Progress:save()
	end
	if Progress:get("Mines Key") == 1 then
		Progress:set("Mines Key", 2)
		Progress:save()
	end
end

function progressCheck()
	playerGraphics()
	if Inventory:get("Jump Boots") == 0 then
		triggerEvent("Start Message")
	end
	if Inventory:get("Jump Boots") > 0 then
		triggerEvent("Jump Boots Effect")
	end
	if Progress:get("Shygon Switcher") > 0 then
		triggerEvent("Shygon Switcher Effect")
	end
	if Progress:get("Shygon Boss") > 0 then
		triggerEvent("Shygon Boss Effect")
	end
	if Progress:get("Mushroom") > 0 then
		triggerEvent("Mushroom Effect")
	end
	if Progress:get("Koopteria Bricks") > 0 then
		triggerEvent("Koopteria Bricks Effect")
	end
	if Progress:get("Koopteria Key") > 0 then
		triggerEvent("Koopteria Key Effect")
	end
	if Inventory:get("Spinjump Boots") > 0 then
		triggerEvent("Spinjump Boots Effect")
	end
	if Progress:get("Fire Flower") > 0 then
		triggerEvent("Fire Flower Effect")
	end
	if Progress:get("Phenpiranha Ice") > 0 then
		triggerEvent("Phenpiranha Ice Effect")
	end
	if Inventory:get("Gravity Cap") > 0 then
		triggerEvent("Gravity Cap Effect")
	end
	if Progress:get("Koopteria Brick Wall") > 0 then
		triggerEvent("Koopteria Brick Wall Effect")
	end
	if Progress:get("Super Leaf") > 0 then
		triggerEvent("Super Leaf Effect")
	end
	if Progress:get("Ice Flower") > 0 then
		triggerEvent("Ice Flower Effect")
	end
	if Inventory:get("Varia Cap") > 0 then
		triggerEvent("Varia Cap Effect")
	end
	if Progress:get("Bob-Bryyo Key") > 0 then
		triggerEvent("Bob-Bryyo Key Effect")
	end
	if Progress:get("Bob-Bryyo Maze") > 0 then
		triggerEvent("Bob-Bryyo Maze Effect")
	end
	if Progress:get("Mines Key") > 0 then
		triggerEvent("Mines Key Effect")
	end
	if Bonus:get("Speed Booster") == 1 then
		triggerEvent("B1")
	end
	if Bonus:get("Recover Up") == 1 then
		triggerEvent("B2")
	end
	if Bonus:get("Flamethrower") == 1 then
		triggerEvent("B3")
	end
	if Bonus:get("Costume1") == 1 then
		triggerEvent("C1")
	end
	if Bonus:get("Costume2") == 1 then
		triggerEvent("C2")
	end
	if Bonus:get("Costume3") == 1 then
		triggerEvent("C3")
	end
end

function playerGraphics()
	if Bonus:get("Costume1") == 1 then
		Graphics.sprites.mario[1].img = smallCos1
		Graphics.sprites.mario[2].img = superCos1
		Graphics.sprites.mario[3].img = fireCos1
		Graphics.sprites.mario[4].img = raccoonCos1
		Graphics.sprites.mario[5].img = tanookiCos1
		Graphics.sprites.mario[6].img = hammerCos1
		Graphics.sprites.mario[7].img = iceCos1
	elseif Bonus:get("Costume2") == 1 then
		Graphics.sprites.mario[1].img = smallCos2
		Graphics.sprites.mario[2].img = superCos2
		Graphics.sprites.mario[3].img = fireCos2
		Graphics.sprites.mario[4].img = raccoonCos2
		Graphics.sprites.mario[5].img = tanookiCos2
		Graphics.sprites.mario[6].img = hammerCos2
		Graphics.sprites.mario[7].img = iceCos2
	elseif Bonus:get("Costume3") == 1 then
		Graphics.sprites.mario[1].img = smallCos3
		Graphics.sprites.mario[2].img = superCos3
		Graphics.sprites.mario[3].img = fireCos3
		Graphics.sprites.mario[4].img = raccoonCos3
		Graphics.sprites.mario[5].img = tanookiCos3
		Graphics.sprites.mario[6].img = hammerCos3
		Graphics.sprites.mario[7].img = iceCos3	
	elseif Inventory:get("Space Jump Boots") > 0 then
		Graphics.sprites.mario[1].img = smallSpaceJump
		Graphics.sprites.mario[2].img = superSpaceJump
		Graphics.sprites.mario[3].img = fireSpaceJump
		Graphics.sprites.mario[4].img = raccoonSpaceJump
		Graphics.sprites.mario[6].img = hammerSpaceJump
		Graphics.sprites.mario[7].img = iceSpaceJump
	elseif Inventory:get("Hi-Jump Boots") > 0 then
		Graphics.sprites.mario[1].img = smallHiJump
		Graphics.sprites.mario[2].img = superHiJump
		Graphics.sprites.mario[3].img = fireHiJump
		Graphics.sprites.mario[4].img = raccoonHiJump
		Graphics.sprites.mario[6].img = hammerHiJump
		Graphics.sprites.mario[7].img = iceHiJump
	elseif Inventory:get("Varia Cap") > 0 then
		Graphics.sprites.mario[1].img = smallVaria
		Graphics.sprites.mario[2].img = superVaria
		Graphics.sprites.mario[3].img = fireVaria
		Graphics.sprites.mario[4].img = raccoonVaria
		Graphics.sprites.mario[7].img = iceVaria
	elseif Inventory:get("Gravity Cap") > 0 then
		Graphics.sprites.mario[1].img = smallGravity
		Graphics.sprites.mario[2].img = superGravity
		Graphics.sprites.mario[3].img = fireGravity
		Graphics.sprites.mario[4].img = raccoonGravity
		Graphics.sprites.mario[7].img = iceGravity
	elseif Inventory:get("Spinjump Boots") > 0 then
		Graphics.sprites.mario[1].img = smallSpinJump
		Graphics.sprites.mario[2].img = superSpinJump
		Graphics.sprites.mario[3].img = fireSpinJump
	elseif Inventory:get("Jump Boots") > 0 then
		Graphics.sprites.mario[1].img = nil
		Graphics.sprites.mario[2].img = nil
	else
		Graphics.sprites.mario[1].img = smallStart
	end
end

function onNPCKill(eventObj, killingNPC, killReason)
	if (killReason == 1 or killReason == 2 or killReason == 3 or killReason == 5 or killReason == 7 or killReason == 8) and not(killingNPC.id == 13 or killingNPC.id == 32 or killingNPC.id == 134 or killingNPC.id == 255 or killingNPC.id == 265) then
		randValue = rng.randomInt(1, 15)
		if Progress:get("Mushroom") == 0 then
			randValue = 0
		end
		if (randValue == 1) then
			NPC.spawn (250, killingNPC.x, killingNPC.y, player.section)
			playSFX(56)
		end
	end
end
(Sorry it's so much, I don't know what's essential to find the problem)

TL;DR - All of the variables update correctly and persist throughout levels except Inventory:get("Spinjump Boots") which resets to 0 upon exiting and re entering the level, but setting the value again causes it to stick.

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: (Help) Data Set Value Reverting to 0

Postby Hoeloe » Sat Jun 03, 2017 3:15 am

I don't see anything immediately wrong there. The code is very hard to read, though.

I'd suggest to make things more readable, you get the hang of using "else" statements, like:

Code: Select all

if(a) then
  dostuff();
elseif(b) then
  domorestuff();
else
  dodifferentstuff();
end
Also, this part of code can be much neater:

Code: Select all

 
stars = NPC.get(196, -1)
 if(table.getn(stars) > 0) then
        for i=1,table.getn(stars) do
            stars[i]:mem(0xA0, FIELD_DFLOAT, 0)
         stars[i]:mem(0x108, FIELD_DFLOAT, 0)
        end
    end
If you write it like this:

Code: Select all

for k,v in ipairs(NPC.get(196, -1)) do
            v:mem(0xA0, FIELD_DFLOAT, 0)
         v:mem(0x108, FIELD_DFLOAT, 0)
        end
You also don't need to "save" the data table if all you're doing is using "get". You only need to save after you "set" data.

None of these things will fix your issue, but they might make your code easier to read and so easier to locate the problem.

That said, I've looked through your code and I think it's more likely the issue is with your event system, not your Lua, since the variable is set up in exactly the same way as all the others.

The0x539
Eerie
Eerie
Posts: 751
Joined: Fri Jan 22, 2016 8:02 pm

Re: (Help) Data Set Value Reverting to 0

Postby The0x539 » Sat Jun 03, 2017 10:20 am

Also on the subject of the generic for loop, you can do something along the lines of this, and with a little work this can also be applied to, say, your onEvent and playerDeath functions.
(functions like initialize and playerDeath, where they're only being called from within the file, should be local as well)

Code: Select all

local inventory_items = {"Jump Boots","Spinjump Boots","Varia Cap","Hi-Jump Boots","Space Jump Boots"}
local progress_items = {"Shygon Switcher","Shygon Boss","Mushroom","Koopteria Bricks","Koopteria Key","Fire Flower","Phenpiranha Ice","Koopteria Brick Wall","Super Leaf","Ice Flower","Bob-Bryyo Key","Bob-Bryyo Maze","Mines Key"}
local bonus items = {"Speed Booster","Recover Up","Flamethrower","Costume1","Costume2","Costume3"}

local function initialize()
   for _,v in ipairs(inventory_items) do
      if Inventory:get(v) == nil then
         Inventory:set(v,0)
      end
   end
   Inventory:save()
   for _,v in ipairs(progress_items) do
      if Progress:get(v) == nil then
         Progress:set(v,0)
      end
   end
   Progress:save()
   for _,v in ipairs(bonus_items) do
      if Bonus:get(v) == nil then
         Bonus:set(v,0)
      end
   end
   Bonus:save()
end

LM280
Monty Mole
Monty Mole
Posts: 121
Joined: Wed Jan 15, 2014 7:10 pm

Re: (Help) Data Set Value Reverting to 0

Postby LM280 » Sat Jun 03, 2017 1:31 pm

The0x539 wrote:functions like initialize and playerDeath, where they're only being called from within the file, should be local as well
Question, I made the functions that are only called within the file local, but I get an error where onStart() tried to call progressCheck(), but I get an error that says it was trying to call global progressCheck() which is nil. How do I specify local when I call it?

The0x539
Eerie
Eerie
Posts: 751
Joined: Fri Jan 22, 2016 8:02 pm

Re: (Help) Data Set Value Reverting to 0

Postby The0x539 » Sat Jun 03, 2017 1:42 pm

Luigimario280 wrote:
The0x539 wrote:functions like initialize and playerDeath, where they're only being called from within the file, should be local as well
Question, I made the functions that are only called within the file local, but I get an error where onStart() tried to call progressCheck(), but I get an error that says it was trying to call global progressCheck() which is nil. How do I specify local when I call it?
Huh. Not what I expected, but assuming what you did is just put a "local" before "function progressCheck()" then I wouldn't know how to get around that. Maybe a quirk, maybe a little slip-up, hard to tell. Not a huge deal if this is for an episode, though, which it is.

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: (Help) Data Set Value Reverting to 0

Postby Hoeloe » Sat Jun 03, 2017 4:29 pm

If functions are local, they must be defined earlier than they are used, which means you need to move the function definition above where it's first used in the code.

LM280
Monty Mole
Monty Mole
Posts: 121
Joined: Wed Jan 15, 2014 7:10 pm

Re: (Help) Data Set Value Reverting to 0

Postby LM280 » Sun Jun 04, 2017 12:17 am

Hoeloe wrote:If functions are local, they must be defined earlier than they are used, which means you need to move the function definition above where it's first used in the code.
Thank you! That worked at least.


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 2 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari