[Shift]+Lowercase Letter = Capital Letter?(Demo/Full Source) (SOLVED)


#1

Hi,

How do we get capital letters (shift+lowercase letter)?
Code below does not work for capital letters?

capitalOffset = 0
if ( action_id == hash("KeyShift") ) then
	capitalOffset = 26
end

for index = 0, 64 do
	if (  action_id == hash( string.format("Key%d", index) ) and action.pressed and self.active  ) then
		node = gui.get_node( string.format("Char%d", index) )
		if (ScreenFadeAlpha == 0) then
			if (index > 25 and index < 52) then
				index = index - capitalOffset
				node = gui.get_node( string.format("Char%d", index) )
			end
		
			gui.set_scale( node, vmath.vector3(0.75, 0.75, 1) )

			msg.post("level:/Audio#MenuClick", "play_sound", {delay = 0, gain = EffectsVolume})
							
			if (NewHighScoreNameIndex < 13) then
				if (index < 26) then
					NewHighScoreName = NewHighScoreName .. string.format("%c", 65+index)
					NewHighScoreNameIndex = NewHighScoreNameIndex + 1
				elseif (index < 52) then
					NewHighScoreName = NewHighScoreName .. string.format("%c", 97+index-26)
					NewHighScoreNameIndex = NewHighScoreNameIndex + 1
				elseif (index < 52+10) then
					NewHighScoreName = NewHighScoreName .. string.format("%c", 48+index-52)
					NewHighScoreNameIndex = NewHighScoreNameIndex + 1
				elseif (index == 62) then
					NewHighScoreName = NewHighScoreName .. "+"
					NewHighScoreNameIndex = NewHighScoreNameIndex + 1
				elseif (index == 63) then
					NewHighScoreName = NewHighScoreName .. " "
					NewHighScoreNameIndex = NewHighScoreNameIndex + 1
				end
			end
			
			if (index == 64 and NewHighScoreNameIndex > 0) then
				NewHighScoreName = NewHighScoreName:sub(1, -2)
				NewHighScoreNameIndex = NewHighScoreNameIndex - 1
			end						

			label.set_text("#NewHighScoreName", NewHighScoreName)

			DelayAllUserInput = 10
		end
	end
end

#2

I am hoping someone could make the above work.
I really want the character buttons to “click”(scale) when player types on the keyboard…


#3

What I have now is HERE
(press [START] on title screen to run new high score name input)

Full project is on GitHub HERE


#4

I’m not 100% sure what the code does, but it might be a bit unnecessarily complex? You should just be able to listen for a text input trigger. You will also get upper or lower case based on shift key usage already applied… :slight_smile:

Simple usage example here.


#5

Looked at text input…
I would work, but I want to link the key pressed on the keyboard to the corresponding character button.
Would like the character button to animate when it’s key on keyboard is pressed.
Don’t see an easy way to do the above…


#6

A better question is:
Is it possible to get a capital letter using “Key Triggers”?


#7

I’m not sure I understand your problem, I see no issue with using text triggers?
Just lookup the correct GUI node using action.text. Something like;

local node_id = gui.get_node("key_node_" .. action.text:lower())

This of course expects that you have named all your visual buttons key_node_a, key_node_b, key_node_c etc… (Or use action.text:upper() if they are named key_node_A etc.)

Please note that this information is easily available in the documentation; https://www.defold.com/ref/string/#string.lower:s


#8

New high score name input is 100% functional, many thanks!