How to: making a name-entry "keyboard"

Perhaps in your Pulp game, the player can enter their name or some other short string. I made a little script that provides a name entry feature like what you would've seen on arcade cabinets (with a joystick and no keyboard).

name entry

The short story is, the player is hidden, and as they move between the 3 slots, their up-down movement steps through an array from 1 to 26. Then another function converts those numbers into letters (yes, it's a very long chain of if-then.) Then a string is built from the 3 values, and your game now has a name variable to use wherever.

That's it!

Name Entry.json.zip (5.0 KB)

11 Likes

I just had to get this to work with the crank too, I've left the button functionality in as well for fine tuning the letter, but now you can zoom right to the end! (probably not quite as practical but it's the playdate :crank:)

Name Entry (crank).json.zip (5.0 KB)

5 Likes

@Neven this excellent of you to share this, i've been using exactly this method to fake a cursor on a computer screen (for selecting an item) and was going to share it but you've beat me to the punch lol!

cpuscreen

Loads of applications for this kind of logic.

6 Likes

This is great! This concept is so much nicer to choose the level in my Pulp game compared to the menu function!

Untitled

I used Benji's code for the crank support, but simplified things since I only need to display numbers.

In the player's update function:

	elseif event.room=="game_menu" then
		
		// scroll through level numbers, ranging from 1 to 20
		if event.dy==1 then
			if level>1 then
				level--
			end
			
		elseif event.dy==-1 then
			if level<20 then
				level++
			end
		end
		
	end

In the player's draw event handler:

		// print level number after selected from menu
		if level<10 then
			label "{level}" at 18,6
		else
			label "{level}" at 17,6
		end

... then in the player's confirm PulpScript:

	elseif event.room=="game_menu" then
		// once level is selected, open menu to determine game speed
		tell event.room to
			call "gamespeed_menu"
		end
	end

Thanks for the inspiration!

3 Likes

@Mattgames - It would be really interesting to see how you've dealt with all this menu stuff in general. If your still willing to share it would be a great reference...

2 Likes

Yeah no worries at all.

Mostly it's just storing a var then doing a check in update. I'll post some bits of code below but it's chopped up from the game code, so might not be complete.

In player:


on load do
citem = 1   // the variable we're gonna use for cursor positions positions
cposy = 2  // and lock the y
	playerx = event.px   //log player locations
	playery = event.py
end

on enter do
	
	// make sure cursor doesn't go too fast
	if event.room=="computer" then
		config.inputRepeatDelay = 0.2
	end
end

//when A is pressed (to access the computer)
on confirm do
	// tell the current tile to do stuff
	tell playerx,playery to
// Tell the floor tile (item we're standing on) to call the function to move to the computer room
	call "computermove" 
end

//do all of the logic for what happens when you press stuff on screen here, so if citem==1, 2, 3, etc.
//do a series of if/esls statements for each citem variable (ie, the position of the cursor so the selected
// item. can use ask/say or whatever nested in these ifs no trouble.
                if event.room=="computer" then
		// item 1 on comp screen
		if citem==1 then
                end 
                end

end


end

//when B is pressed
on cancel do
	// exit out of computer
	if event.room=="computer" then
		// reset selected comp item
		citem = 1
		// return to the apartment after using computer
		goto 4,7 in "other room"
	end
end


on draw do
if event.room=="computer" then
//ensure the player is always the computer pointer sprite every single frame
//this makes sure no other logic leaks in, expensive, but worth it.
swap "compsel"  
end
end

on update do
     // chuck the player location in a variable for use later.
	playerx = event.px
	playery = event.py

	// computer cursor movement  add 1 if we press up, remove 1 if we press down
	// this is used for calculating the cursor position later on
	if event.room=="computer" then
		// pressed down
		if event.dy==1 then
			citem++
			// say "citem{citem}"   //uncomment for debugging if needed
		end
		
		// pressed up
		if event.dy==-1 then
			citem--
			// say "citem{citem}"   //uncomment for debugging if needed
		end
		
		
		// check what Citem we're on and se the cursor (player) position
		// we need the wait because... reasons. Infinite loop of some kind? bug maybe? who knows
		wait 0.1 then
			// make sure we don't go somewhere wrong with the cursor
			if citem==0 then
				citem = 4
				cposy = 11
				goto 13,cposy
			elseif citem==5 then
				citem = 1
				cposy = 2
				goto 13,cposy
				// end of checks for top and bottom of screen
			elseif citem==1 then
				// and move the cursor to only these positions
				cposy = 2
				goto 13,cposy
			elseif citem==2 then
				cposy = 5
				goto 13,cposy
			elseif citem==3 then
				cposy = 8
				goto 13,cposy
			elseif citem==4 then
				cposy = 11
				goto 13,cposy
			end
			// end of wait for if calculation
		end
		
		
	end

end

and in the floor tile (item) that activates the computer use:

on collect do
	// nothing obvs
end

on computermove do
	goto 13,2 in "computer"
end

@WoolyPolygon I think that's all of it, might not be drop in code but should be enough to get you started! Let me know if it helps :slight_smile: for the cursor position on screen i'm effectively teleporting the player around the room to a set of locked/predefined positions (that's what all the "goto" logic is in the update function. Also apologies, my code and comments are not exactly tidy.

*Edited to update/include a missing variable from the code.

1 Like