Page 1 of 1

Cat & Penguin Powerups (help needed)

Posted: Mon Aug 14, 2017 8:30 am
by Gaming-Dojo
Hello Guys.
I tried to make apis for cat and penguin powerups as I think these would be cool to have in SMBX but they don't work without producing an error.
These are the codes:
Cat:

Code: Select all

local cat = {}

local climbTimer = 10

function cat.oninitAPI()
registerEvent(cat, "onTickEnd", "onTickEnd", false)
end

function cat.onTickEnd()
if player.powerup == 4 then
   if player:mem(0x14C,FIELD_WORD) ~= 0 or player:mem(0x148,FIELD_WORD) ~= 0 then
      player:mem(0x40,FIELD_WORD,3)
	  climbTimer = climbTimer - 1
	  end
   if climbTimer == 0 then
      player:mem(0x40,FIELD_WORD,2)
      end
	     if player:mem(0x14C,FIELD_WORD) == 0 and player:mem(0x148,FIELD_WORD) == 0 then
		    climbTimer = 10
		 end
	  end
end
	 
return cat
Penguin:

Code: Select all

local penguin = {}

local can_slide = false

function penguin.onInitAPI()
     registerEvent(penguin, "onTick", "onTick", false)
	 end


function onTick()
   if player:mem(0x16C,FIELD_WORD,1)  then 
   can_slide = true
   end

 if can_slide == true then
    if player.downkeypressing == true then 
	player:mem(0x3C,FIELD_WORD,1)
 end
    end
		Graphics.sprites.mario[7].img = Graphics.loadImage("penguin_mario.png")
   end

return penguin
Can you say me what's wrong with these codes.For the penguin, I suppose that there's an issue with recognizing when sliding's ready/with building up speed.
Greetings,yoshiegg.

Re: Cat & Penguin Powerups (help needed)

Posted: Mon Aug 14, 2017 8:34 am
by Hoeloe
yoshiegg wrote:they don't work without producing an error
Please post the error message. The message exists for a reason, and it gives vital information about what the problem is.

That said, the cat powerup has one too many "end" statements.

It's recommended to format things like this:

Code: Select all

if(someCondition) then
    if(someOtherCondition) then
        --do some things
    end
end
Each open block should step in, each end should step back out again. This makes it very obvious if there's a mismatch somewhere, which would help avoid this issue.

Also don't use Graphics.loadImage inside onTick. Save it to a variable outside the function and use that.

Re: Cat & Penguin Powerups (help needed)

Posted: Mon Aug 14, 2017 8:55 am
by Gaming-Dojo
There was really no error notification but the codes don't work as they should though.I now increased the timer of the cat as a climbing of 10 ticks wouldve been hardly recognizable.
So that's my cat code now:

Code: Select all

local cat = {}

local climbTimer = 300

function cat.oninitAPI()
registerEvent(cat, "onTickEnd", "onTickEnd", false)
end

function cat.onTick()
  if player.powerup == 4 then
   if player:mem(0x14C,FIELD_WORD) ~= 0 or player:mem(0x148,FIELD_WORD) ~= 0 then
      player:mem(0x40,FIELD_WORD,3)
	  climbTimer = climbTimer - 1
	  end
   if climbTimer == 0 then
      player:mem(0x40,FIELD_WORD,2)
   end
	     if player:mem(0x14C,FIELD_WORD) == 0 and player:mem(0x148,FIELD_WORD) == 0 then
		    climbTimer = 10
		 end
  end
end
	 
return cat

Re: Cat & Penguin Powerups (help needed)

Posted: Mon Aug 14, 2017 8:59 am
by The0x539
I see you're trying to modify the player's "climbing state", as used by fences and vines and stuff. I don't feel like that's going to work, I feel like vanilla code will immediately detect that the player isn't anywhere near any climbable objects, and kick you right out of that state. Try just messing with speed or upward jumping force.