RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[Solved-ish]text input prompt?

0 Members and 2 Guests are viewing this topic.

***
Rep:
Level 82
We learn by living...
I'm trying to make a small window for "description" that when it becomes selected/active, the string that is
"description" can be deleted and accept keyboard input such as A-Z, spacebar, and backspace commands. In other words, a textbox. When hitting 'escape' or some other designated key, whatever is in the box becomes the new standard.

I tried some messy stuff I found on the web but it just spits out the length of my string:
Code: [Select]
def STDOUT.write(prompt)
  if prompt == "\n"
    super
  else
    super "> #{prompt}"
  end
rescue Errno::EBADF
  def self.write(prompt)
  end
end
 
   
  def refresh
    self.contents.clear
    self.contents.font.color = text_color(6)
 
   
    checkz = $stdout.write( "This is a test\n" )
    self.contents.draw_text(0, 0, 100, 32, checkz.to_s)
    end

in this case, it spat out 17 and then vanished a few seconds later.
« Last Edit: January 12, 2011, 10:07:44 PM by shintashi »

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, you definitely need a full keyboard input script. I recommend getting Blizzard's Custom Controls from his Tons of Addons script at Chaos Project and playing around with it.

***
Rep:
Level 82
We learn by living...
Well, you definitely need a full keyboard input script. I recommend getting Blizzard's Custom Controls from his Tons of Addons script at Chaos Project and playing around with it.

I've got SDK and Aleworks input module


edit: I got Aleworks input keys working, here's a demo of the letter "A" and the Backspace key, but the key listener is too sensitive and repeats too quickly. Any ideas on slowing it down? Otherwise if I was to type something like "this spell heals one target creature" it would read like

"tttthhhhhhiiss sppppeeeell hhhhhhheeeaaaaaaalllsssss ooooonnnee ttargggeett ccreeeaattture"

Code: [Select]
class Window_0 < Window_Base

  def initialize
    super(0, 0, 640,100)
    self.contents = Bitmap.new(width-32, height-32)
    #self.contents.font.name = "Arial" 
    #self.contents.font.size = 24
    refresh
  end

 
  $description ="[DESCRIPTION]"
   
  def refresh
    self.contents.clear
    self.contents.font.color = text_color(8)

   
    if Input.press?(65)
    a = "A"
$description = $description + a.to_s
    end 
 
    #backspace
    if Input.press?(8)
$description = $description.chop
    end 
 
   
    self.contents.draw_text(0, 0, 500, 32, $description.to_s)
  end
 
  def update
    if Graphics.frame_count / Graphics.frame_rate != @total_sec
      refresh
    end
  end
 
end
« Last Edit: January 10, 2011, 12:54:47 AM by shintashi »

***
Rep:
Level 82
We learn by living...
I figured out I could put 'sleep 0.1' to 'sleep 0.3' right after and it prevents the repeat from being too stupid, but I'm not sure how well that's going to pan out.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Use trigger? or repeat? instead of press?

***
Rep:
Level 82
We learn by living...
Use trigger? or repeat? instead of press?

repeat? looks like it works best. trigger? is nice and would probably work for something besides letters like transition between screens. Btw, any idea how to temporarily disable the regular "C" input command? 

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Most direct way would be through aliasing the Input methods and returning false whenever Input::C is sent through, but that's not necessarily the smartest way. The best way would be to do it in the scene where you want to relieve it of its function, but I don't know what scene that is so I can't help you.

***
Rep:
Level 82
We learn by living...
Most direct way would be through aliasing the Input methods and returning false whenever Input::C is sent through, but that's not necessarily the smartest way. The best way would be to do it in the scene where you want to relieve it of its function, but I don't know what scene that is so I can't help you.

This is the scene:
Code: [Select]
$scene = Skill_Editor.new

I've got A-Z, comma, space, backspace, and period installed, but I can't seem to get the Shift+other key combo working.

aleworks claims
Code: [Select]
#-- Example 3 --
#    Input.trigger?([[Keys::SHIFT, Keys::ESCAPE]])
#   It'll return true if the keys SHIFT and ESCAPE are being pressed.

but what actually happens is both keys work independently to produce the effect whether or not the mate is being pushed.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
That's not really what I meant - I meant if you don't want Input::C to do anything special, then you should just disable it within the scene. It only does something if the scene you're in tells it to do something.

In any case, I don't know anything about this script you are using so I can't really tell you what's going on - I can say that trigger? is not a good one to use if you are checking two keys as it will mean they both have to be touched at the exact same time.

The way I would handle that is have the Input.repeat? for the regular keys and, then when it comes to choosing which key is included, do a check for Input.press? (Keys::SHIFT), rather than trying to do a combination thingy.

***
Rep:
Level 82
We learn by living...
That's not really what I meant - I meant if you don't want Input::C to do anything special, then you should just disable it within the scene. It only does something if the scene you're in tells it to do something.

In any case, I don't know anything about this script you are using so I can't really tell you what's going on - I can say that trigger? is not a good one to use if you are checking two keys as it will mean they both have to be touched at the exact same time.

The way I would handle that is have the Input.repeat? for the regular keys and, then when it comes to choosing which key is included, do a check for Input.press? (Keys::SHIFT), rather than trying to do a combination thingy.

could you give an example of "a" and "A"? Here's my base snippet:

Code: [Select]
    if Input.repeat?(65)
    a = "a"
$description = $description + a.to_s
    end

    if Input.press?(16) #16 is shift key
    a = "A"
$description = $description + a.to_s
    end


*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Doing it through individual keys like that is super nasty - I would imagine the Input module you are using would allow you to retrieve the keys being triggered without checking each one individually - I would suggest that you use that.

In any case, the idea would be this:

Code: [Select]
if Input.repeat? (65)
  a = Input.press? (16) ? "A" : "a"
  $description += a
end

But as I said again, you shouldn't have to go through each key individually like that - the Input module you are using should probably allow you to retrieve the keys being repeated, pressed, and triggered in separate arrays, and that is a much better way to write this script. You can use the chr method on an integer to return the letter corresponding. Ie. 65.chr would change to "A".

***
Rep:
Level 82
We learn by living...
the shortform definitely works. Right now I'm trying to see how I can switch this 'keyboard' thing on and off, because if I can, the power to edit strings on the fly could be huge - like passwords, lines from poetry, spells, riddles and so on.

As is, as soon as $scene = Skill_Editor.new  kicks on, and runs

Code: [Select]
class Skill_Editor

def initialize(menu_index = 0)
   @menu_index = menu_index #Store the cursor position
end 
 
def main
   @window_0=Window_0.new
   @window_0.y=380
@window_0.visible = false
@window_0.active = false
...

the keyboard script in window_0 is active, even if window_0 itself is not active. So When I start hitting backspace and typing, even if the window is invisible and inactive, when I activate that window, whatever I typed or deleted displays as such. Toggling it on and off with

if window_0.active == true
(keyboard stuff)
end

crashed instantaneously.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, that largely depends on where you are putting the processing for it. Putting it inside a conditional like that should certainly work, provided that is in the same scene as @window_0 and stuff outside it doesn't depend on stuff inside it. I don't see why it would crash if it was the same class and you are only calling it after @window_0 has been defined.

A workaround would be to simply clear that keyboard's global variable whenever you first make the window active. But that's a messy way to do it - an intelligent positioning of the Keyboard interpreting would be a better way.

***
Rep:
Level 82
We learn by living...
I turned the keyboard thing into a method and moved it into the main section of my scene:skill_editor.
Also added an enter key to make the changes to skill descriptions permanent. Hypothetically, whatever skill.description or skill.name is to be edited is copied to $description, then you can edit it with keyboard, then when you hit enter, it copies the info from $description to the skill.description or skill.name. You can then exit the editor with the escape key.

So far it works for one window and description; getting the idea to work for a second window, like the skill's name is going to be the next step.


Edit:
This double window thing has been a nightmare. I've been working on it for hours but so far the closest I got was typing blind and having changes take place after hitting enter. I'm really beginning to think my $description thing needs to be an array like $rename=["[DESCRIPTION]", "[TITLE]"], but i think changing my method right now seems like a "if it aint broke, dont fix it" situation where some other way of using this seems more prudent.

edit(12:10AM):
I got it working. Instead of using window_0.active == true, I created a new set of booleans titled
$win0 and $win8, and set both to false.
« Last Edit: January 12, 2011, 08:12:32 AM by shintashi »