(Solved) Link player.speedX bug?

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?
Shadowblitz16
Fighter Fly
Fighter Fly
Posts: 60
Joined: Tue Aug 09, 2016 1:41 pm

(Solved) Link player.speedX bug?

Postby Shadowblitz16 » Mon Jun 26, 2017 12:30 pm

hello I was working on implementing link's wall clang from zelda 2 however I found a bug where link's speedX doesn't move him if he is on the ground.
this is bad because I need to increment his speed the opposite way he is facing when he stabs a wall.

I tried setting the memory values for sliding and slippery but they don't seem to do anything.
does anybody know how to get around it?

this is my code so far..

Code: Select all


local hud = loadSharedAPI("hud")

local colliders = loadSharedAPI("colliders")

--variables
isInitialized = false

--config
local jumpHeight   = 6
local bounceHeight = 2

local attackSpeed  = 2
local jumpSpeed    = 2
local walkSpeed    = 2
local runSpeed     = 5

--Items
local hasCandle      = false
local hasBoomarang   = false
local hasBombs       = false
local hasBoots       = false
local hasBow         = false
local hasGloves      = false
local hasHookshot    = false
local hasRing        = false

-- health, magic, and ammo
local health         = 0
local healthMax      = 4
local magic          = 0
local magicMax       = 4
local arrows         = 0
local arrowsMax      = 20
local bombs          = 0
local bombsMax       = 10

--sounds
local sfx_swordClang = Audio.SfxOpen("Sounds/AOL_Sword_Clang.ogg")

local function blockFilter(b)
	return not b.isHidden;
end

local function checkForSwordClank()

	local colliding = false
	if (player:mem(0x106, FIELD_WORD)     == -1) then
		if (player:mem(0x114, FIELD_WORD) ==  8) then
			local box = colliders.Box(player.x - 28, player.y+22, 32, 8)
			colliding = colliders.collideBlock(box, colliders.BLOCK_SOLID, blockFilter)
			
			--box:Debug(true)
		elseif (player:mem(0x114, FIELD_WORD) == 7) then
			local box = colliders.Box(player.x - 28, player.y+16, 32, 8)
			colliding = colliders.collideBlock(box, colliders.BLOCK_SOLID, blockFilter)
			
			--box:Debug(true)
		end
	elseif (player:mem(0x106, FIELD_WORD) ==  1) then
		if (player:mem(0x114, FIELD_WORD) ==  8) then
			local box = colliders.Box(player.x + 20, player.y+22, 32, 8)
			colliding = colliders.collideBlock(box, colliders.BLOCK_SOLID, blockFilter)
			
			--box:Debug(true)
		elseif (player:mem(0x114, FIELD_WORD) == 7) then
			local box = colliders.Box(player.x + 20, player.y+16, 32, 8)
			colliding = colliders.collideBlock(box, colliders.BLOCK_SOLID, blockFilter)
			
			--box:Debug(true)
		end
	end
	return colliding
end

local function checkForCeiling()
	local colliding = false
	local box = colliders.Box(player.x + 3, player.y - 32, 20, 32)
	colliding = colliders.collideBlock(box, colliders.BLOCK_SOLID, blockFilter)
	
	return colliding
end

local function checkForFloor()
	local colliding = false
	local box = colliders.Box(player.x, player.y, 20, 32)
	colliding = colliders.collideBlock(box, colliders.BLOCK_SOLID, blockFilter)
	
	return colliding
end

function onTick()

	if (player.character == CHARACTER_LINK) then
		if (isInitialized == false) then
			Defines.jumpheight          = jumpHeight
			Defines.jumpheight_bounce   = bounceHeight
			Defines.player_walkspeed    = walkSpeed
			Defines.player_runspeed     = runSpeed
			Defines.player_link_fairyVineEnabled = false
				
			isInitialized = true
		else
			if (checkForSwordClank() == true) then
				if (Audio.SfxIsPlaying(0) == 0) then 
					Audio.SfxPlayCh(0, sfx_swordClang, 0)
				end
				
				if (player:mem(0x106, FIELD_WORD)     ==  -1) then
					if (checkForFloor() == true) then player:mem(0x3C, FIELD_WORD, -1) end
					player.speedX = player.speedX + 16
				elseif (player:mem(0x106, FIELD_WORD) ==   1) then
					if (checkForFloor() == true) then player:mem(0x3C, FIELD_WORD, -1) end
					player.speedX = player.speedX - 16
				end
			end
			Text.print(player:mem(0x114, FIELD_WORD), 0, 32);
			if (player.speedX >  walkSpeed) then player.speedX =  walkSpeed end
			if (player.speedX < -walkSpeed) then player.speedX = -walkSpeed end
			--if (player:mem(0x14, FIELD_WORD) > 8) then player:mem(0x14, FIELD_WORD, 0) end
		end
	end
end
Last edited by Shadowblitz16 on Mon Jun 26, 2017 9:47 pm, edited 1 time in total.

User avatar
timocomsmbx2345
Ninji
Ninji
Posts: 825
Joined: Sat Feb 06, 2016 1:44 pm
Current Project: i dont even know anymore. . . .
Chat Username: same as my username
Contact:

Re: Link player.speedX bug?

Postby timocomsmbx2345 » Mon Jun 26, 2017 12:32 pm

how about try and make a power-up where you can shoot a fireball and an iceball at the same time
SMBX 2.0 β4 is here!!! How about 2.0 β5?
ImageImage
Image
Meepyglobix wrote:DON'T SAY "38A??". OR I'll SHOOT YOU.
Spoiler: show
Image Thanks Pixelpest!!!!
Image
Image

User avatar
The0x539
Nipper Plant
Nipper Plant
Posts: 751
Joined: Fri Jan 22, 2016 8:02 pm
Current Project: SMBX2

Re: Link player.speedX bug?

Postby The0x539 » Mon Jun 26, 2017 12:54 pm

Player offset 0x138 might help.

Shadowblitz16
Fighter Fly
Fighter Fly
Posts: 60
Joined: Tue Aug 09, 2016 1:41 pm

Re: Link player.speedX bug?

Postby Shadowblitz16 » Mon Jun 26, 2017 2:52 pm

Thank You for the replies.
however player offset 0x138 does not work. not even in the air.

User avatar
The0x539
Nipper Plant
Nipper Plant
Posts: 751
Joined: Fri Jan 22, 2016 8:02 pm
Current Project: SMBX2

Re: Link player.speedX bug?

Postby The0x539 » Mon Jun 26, 2017 3:41 pm

You making sure to interpret it as a float rather than a word?

Shadowblitz16
Fighter Fly
Fighter Fly
Posts: 60
Joined: Tue Aug 09, 2016 1:41 pm

Re: Link player.speedX bug?

Postby Shadowblitz16 » Mon Jun 26, 2017 5:00 pm

ok so it works kinda but not really.

it basically adds to link's position not his velocity.
also it doesn't effect him much unless I set it to something high like 16.0, but then it makes him fly very far away when he does it in the air.

Also I have tested player.speedX outside of the just Changed statement and it does work so I'm pretty sure its a bug with it being executed for only one frame.

Code: Select all

			--player.speedX =  1.5 --works
			if (justClanged) then
				Audio.SfxPlayCh(-1, sfx_swordClang, 0)
				--player.speedX =  1.5 --doesn't work
				
				if (player:mem(0x106, FIELD_WORD)     ==  -1) then
					--player.speedX =  1.5 --doesn't work
				elseif (player:mem(0x106, FIELD_WORD) ==   1) then
					--player:mem(0x138, FIELD_FLOAT, -16.0)
					--player.speedX = -1.5 --doesn't work
				end
			end
			
EDIT: ok so just tested it to make sure and it seems that player.speedX makes him go into his walking animation.
so I'm guessing that speedX is actually the equivalent to a walk function.
and in the air its treated as normal horizontal velocity

do you know how to get around this?

EDIT2: ok so I just made custom variables to do the moving for me

Code: Select all

-- Config
local clangSpeed   = 1.25

-- Variables
	velocityX = 0
	velocityY = 0
	frictionX = 0.1
	frictionY = 0.1

-- Variables for current events
local isClanging     = false;

-- Variables for just triggered events
local justClanged    = false;

-- Sounds
local sfx_swordClang = Audio.SfxOpen("Sounds/AOL_Sword_Clang.ogg")

function onTick()

	if (player.character == CHARACTER_LINK) then
		if (isInitialized == false) then				
			isInitialized = true
		else
			--reset single trigger variables
			justClanged = false
			
			--Check if just clanged
			if     ((checkForSwordClank() == true)  and (isClanging == false)) then isClanging = true  justClanged = true
			elseif ((checkForSwordClank() == false) and (isClanging == true))  then isClanging = false 
			end

			--Perform clang logic
			if (justClanged) then
				Audio.SfxPlayCh(-1, sfx_swordClang, 0)
				if (player:mem(0x106, FIELD_WORD)       ==  -1)  then velocityX = -clangSpeed
				elseif (player:mem(0x106, FIELD_WORD) ==   1)  then velocityX = -clangSpeed
				end
			end
			
			--Move player
			player.x = player.x + velocityX;
			player.y = player.y + velocityY;
			
			--If on ground
			if (player:mem(0x146, FIELD_WORD) == 2) then
			
				-- X Friction
				if   (math.abs(velocityX) > frictionX) then velocityX = velocityX - frictionX*math.sign(velocityX)
				else velocityX = 0
				end

				-- Y Friction
				if   (math.abs(velocityY) > frictionY) then velocityY = velocityY - frictionY*math.sign(velocityY)
				else velocityY = 0
				end
			end
		end
	end
end		


Return to “LunaLua”

Who is online

Users browsing this forum: Google [Bot] and 1 guest