Menu with character's name

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
LsJack
Posts: 4
Joined: Tue May 14, 2024 4:15 pm

Menu with character's name

Post by LsJack »

hi guys, first post here.

my question is how do I create a display name, so the user can write the character's name.
i didn't want to do it like the old games did, to select from letter to letter to create the name.
is there anything about this or how i create this?
User avatar
Ats
Posts: 764
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Menu with character's name

Post by Ats »

Hi LsJack,

Here's a quick loop + key code scanning to type with the keyboard:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZExpression Expression="MyName = &quot;&quot;;"/>
  </OnLoaded>
  <OnUpdate>
    <Repeat Name="LetterRepeat" Count="26">
      <OnIteration>
        <ZExpression>
          <Expression>
<![CDATA[/* Scan letters from A = 65 to Z = 90 */
KeyboardInput.CharCode = 65 + LetterRepeat.Iteration;]]>
          </Expression>
        </ZExpression>
        <KeyPress Name="KeyboardInput" CharCode="90">
          <OnPressed>
            <ZExpression>
              <Expression>
<![CDATA[if (keypress == 0)
{
  keypress = 1;
  /* Convert key code to character */
  MyName += chr(65 + LetterRepeat.Iteration);
}]]>
              </Expression>
            </ZExpression>
          </OnPressed>
          <OnKeyUp>
            <ZExpression Expression="keypress=0;"/>
          </OnKeyUp>
        </KeyPress>
      </OnIteration>
    </Repeat>
  </OnUpdate>
  <OnRender>
    <RenderText TextExpression="MyName"/>
  </OnRender>
  <Content>
    <Variable Name="MyName" Type="2"/>
    <Variable Name="keypress" Type="4"/>
  </Content>
</ZApplication>
User avatar
Kjell
Posts: 1915
Joined: Sat Feb 23, 2008 11:15 pm

Re: Menu with character's name

Post by Kjell »

Hi guys,
Ats wrote: Mon May 20, 2024 12:01 pmHere's a quick loop + key code scanning to type with the keyboard
@Ats: You can do this exact thing a little bit easier actually, like this:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZExpression Expression="MyName = &quot;&quot;;"/>
  </OnLoaded>
  <OnUpdate>
    <KeyPress Name="KeyInput" Keys="ABCDEFGHIJKLMNOPQRSTUVWXYZ">
      <OnKeyDown>
        <ZExpression Expression="MyName += substr(KeyInput.Keys, KeyInput.KeyIndex, 1);"/>
      </OnKeyDown>
    </KeyPress>
  </OnUpdate>
  <OnRender>
    <RenderText TextExpression="MyName"/>
  </OnRender>
  <Content>
    <Variable Name="MyName" Type="2"/>
  </Content>
</ZApplication>
LsJack wrote: Mon May 20, 2024 2:44 ammy question is how do I create a display name, so the user can write the character's name.
@LsJack: The keyboard features in ZGameEditor are primarily meant for controlling things, not for text input. But, with a bit of code you can create your own solution. The question however is, what features do you want/ need exactly?

Attached is a name entry example that supports [space]0-9A-Za-z[-_] as valid characters, the maximum length is 32 characters, supports the Shift key but not Caps Lock ( at the moment .. i could add that if you want ), and Backspace with automatic input-repeat when you hold it long enough.

+ Welcome! :)

K
Attachments
Entry.zgeproj
(9.19 KiB) Downloaded 70 times
LsJack
Posts: 4
Joined: Tue May 14, 2024 4:15 pm

Re: Menu with character's name

Post by LsJack »

Kjell wrote: @LsJack: The keyboard features in ZGameEditor are primarily meant for controlling things, not for text input. But, with a bit of code you can create your own solution. The question however is, what features do you want/ need exactly?
i need exactly that, the player can write the character's name. i am creating a character menu UI to define some characteristics of the character including its name.

the example was perfect, now i just need to understand how it works properly :lol:
Kjell wrote: + Welcome! :)
thanks, i'm from Brazil, delphi developer, i loved the project.
User avatar
Ats
Posts: 764
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Menu with character's name

Post by Ats »

Kjell wrote:You can do this exact thing a little bit easier actually
Whoops. I always thought that 'OnPressed' was the equivalent of 'just pressed' since it is conjugated in the past and not called 'OnPress'. And that 'OnKeyDown' was the opposite... :lol:
User avatar
Kjell
Posts: 1915
Joined: Sat Feb 23, 2008 11:15 pm

Re: Menu with character's name

Post by Kjell »

Hi Ats,
Ats wrote: Tue May 21, 2024 9:39 amI always thought that 'OnPressed' was the equivalent of 'just pressed' since it is conjugated in the past and not called 'OnPress'.
Yea .. this can be a bit confusing as the terminology isn't consistent among platforms / engines :?

Image

K
Post Reply