Moving player with the Crank

I'm wondering how to move the player using the crank. Because the player movement using the directional controls is built-in, I'm not sure what I would need to script to make it move using the crank instead - I assume I need to use the on crank do event, but would it be something similar to making a sprite move around the screen (replacing an adjacent tile with the sprite and deleting its previous location), or is it something different for the player?

I'm trying to make the player move around the screen in a circle with the crank turn

Check out the answer here. Hopefully that points you in the right direction.

1 Like

@Bro-Code has good advice on cancelling out the D-pad movement - effectively you let the player move then move them back.

I wonder if this introduces issues with items though - if you use the dpad to step on an item with default behavior it would be picked up before your code runs to move them back?

As for moving the player with the crank, I expected you to do this:

on crank do
  log "cranked"
  target=event.px
  target+=event.ra
  goto target,event.py
end

but for me that's not working - i get some intervention message about passive listeners... seems i can't use the crank in Pulp Player

I haven't received that error message, it seems to sort of work for me; it moves my player along the x axis, but incredibly quickly (almost instantaneously reaching the edge of the screen) and leaving duplicates behind on some tiles.

It's a start though!

1 Like

I wonder what i need to change to make my browser work with the crank? what browser/OS are you using? i'm on win11 and tried both firefox and chrome. same issue with both. everytime i move the virtual crank i get an error message in the console.

as for the speed issue - event.ra provides the relative angle change in degrees since the last time "crank" was called. so you if you want to move say 1 tile per rotation you'd want to create a variable to store these .ra values over time and move a tile only after it reaches 360 (or -360)

if you choose to setup a nice ratio (perhaps dynamic? move faster if the user cranks faster, that sort of thing) just be careful with division - too many of those will slow things down, so if possible do one division elsewhere to set a variable, then add/subtract/multiply with that variable rather than perform division in the crank function.

1 Like

Also @bitflung sorry, but could you let me know what event.ra refers to? Is there a glossary of thes extensions? I'm gradually learning them from asking individual questions but it would help total code newbies like me to work out some more stuff if there was a list of things like .dx .px etc. as far as I can see it's not included in the Puplscript document.

no worries
event.ra and other event components are documented here:Playdate PulpScript

1 Like

@bitflung are you sure? Double check, I'm wondering if has been removed, or if you have another reference?

Search for .ra on the current version of that page and you will see no results.

(I've had to figure out dx, dy, px, py on my own. I like the brevity of the doc, but a cheat sheet would be useful. If you happen to have your own, it would probably be useful for folks like me and @AdamHopeless )

I've lost some context here - am I sure about what?

I like the idea of a cheat sheet. I'll pull something together and share it

1 Like

You are getting no results because you are searching for .ra, it's documented as just ra (i.e. no preceding dot)

bitflung's link goes to the right part of the documentation

Thanks. Not a flame war here but:

  • In my opinion, .ra search would ideally result in finding a code example where .ra is actually used
  • Searching for ra results in 132 non-relevant results
  • Same goes for aa
  • And neither are described outright. Absolute angle happens to incidentally be named and defined in a related paragraph (that bitflung cited); rotation (?) angle is never named but is somewhat defined (obscurely, with a muddiness about the frame concept.)

User-friendly documentation is one place where "technically correct" isn't the best kind of correct. PulpScript is supposed to be for n00bs as well as experts, I don't think it would be inelegant to offer a bit more guidance.

If you feel like being that helping hand, I've created a crank related post for general learning around aa ra and applications for crank.

Dump any thoughts there and I can edit together into a guide. Next up is ra and it's going to be a steeper learning curve than aa by far. If you've used it and have anything to share, please do.

Sure, I wasn't intending to come across as dismissive, sorry if it seemed that way!

If you want to quickly ctrl-f around the docs as they currently are (for ra or dy or whatever) then put spaces either side, that way you'll cut out all the false positives :slight_smile:

1 Like

Posting for anyone else who stumbles across this:
The problem is ra is not an integer, and this causes the player icon to duplicate and glitch all over the screen.
Use the round function first, eg:

target = event.px
target += event.ra
target = round target
goto target, event.py

The lack of compound expressions gets tedious pretty quickly... especially as you should then add a bounds check on the size of the room (the bottom-right is 24,14)