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.
Text input for loop?

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 82
We learn by living...
I haven't tested this yet, but I was wondering if someone could check it for errors, because I'm not even sure I'm doing this right.

Code: [Select]
for i in 0..25
a = [“a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “j”, “k”, “l”, “m”, “n”, “o”, “p”, “q”, “r”, “s”, “t”, “u”, “v”, “w”, “x”, “y”, “z”]
g = i + 65
if Input.repeat? (g)
@my_variable += a[i]
end
end

I never trust for loops to work.

**
Rep:
Level 82

Code: [Select]
a =%w { a b c d e f g h i j k l m n o p q r s t u v w x y z }
(65..90).each {|i| @my_variable += a[i] if Input.repeat?(i) }

This does the same thing. There are a few subtle differences between for..do loops and using brackets, but the bracket form is how I have always scripted.

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
Assuming you have a non-standard Input.repeat? method which gets the key press according to... it's Virtual-Key Code?... it looks ok (ugly due to lack of proper indention though)

I would suggest changing the range to 65..90 as ForeverZero suggest and use the .chr method. Here is an example which hopefully can help you on your way:
Code: [Select]
str = ''
for i in 65..90
  str += i.chr
end
print str


@ForeverZero:
It definitely does not do the same thing.
Using a literal array is a good idea as you get a tighter and easier to read code.
Note that %w does not interpolate while %W does so using capital W would be a functional equivalent. As interpolation is not required %w is a better choice.

Syntax wise parentheses () are used for the array rather than brackets {} and no spaces must be between %w and (.
Fixing the literal array syntax problems the snippet can look like this:
Code: [Select]
a = %w( a b c d e f g h i j k l m n o p q r s t u v w x y z )
(65..90).each {|i| @my_variable += a[i] if Input.repeat?(i) }
A word of advice is to always test run code snippets before presenting them as you'll find errors such as these which you can be fixed easily and quickly while they may cause more costly confusion for the people you are trying to help. ;)

The second line is more troublesome because the logic rather than the syntax is wrong. Variable g had a purpose because the number check for in Input.repeat? is different from the index. Maybe adding nil will give an error, maybe it won't. That depends on the type @my_variable is.

*hugs*

**
Rep:
Level 82
I didn't test it, for that I am sorry. I'm sure shintashi could have figured it out with one second that I added a space where there shouldn't have been, and get the basic idea.

Thank you for your lesson.  I need to learn Ruby.

***
Rep:
Level 82
We learn by living...
oh, I got a version partially working a while ago, although I'm only sometimes able to find things like "spaces". I make errors all the time, especially in SDK.

Right now I'm trying to cope with "C" interference. If I want to use the spacebar for a command, and not have the letter "C" act like a spacebar, what do I have to do?

*****
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Best IRC Quote2014 Zero to Hero2014 Most Missed Member2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
Really, you'd either have to define your own input module and refer to that or alter the existing input module - which you shouldn't do.
I'm currently on a computer that doesn't have RMs, so I can't show you what I mean. I saw a command in a script somewhere that has exactly what you want in it. I'll find it later.
it's like a metaphor or something i don't know

**
Rep:
Level 82
You could use the Win32API class to get keyboard input. I am can't remember all the exact ranges off the top of my head, but I'm sure google could answer you quickly enough. Here would be a quick example though just to show the basics how it works. Just place this little scriptlet anywhere in your editor outside of a class. I'm sure you can figure out how to simply include it in your loop.

Code: [Select]
    @input = Win32API.new('user32','GetAsyncKeyState','i','i')
    loop {
      Graphics.update
      (0..500).each {|i|
        if @input.call(i) & 0x01 == 1
          p i.chr
          # Obviously instead of "p" to show the letter, you can add the letter to an array
          # in your script.
          break
        end
      }
    }

*****
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Best IRC Quote2014 Zero to Hero2014 Most Missed Member2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
Alternatively, you could do that ^.
You should do that.
it's like a metaphor or something i don't know