Skip to main content

News

Topic: Key characters (Read 6783 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
Key characters
So we know you can use characters like so "\224"

So if i wanted to write that out in a textbox that the user controls, then take that string to add that character, how would i?

It seems to refuse "/" because it is a special character (ie appears replaced by the appropriate character)

so "\" + "224"
would not work because it wont accept "\" on its own?

any ideas?

Re: Key characters
Reply #1
You would have to do the conversion yourself, e.g.

Code: [Select]
function convert(text) {
  return text.replace(/\\([\d]+)/, function (match) {
    return String.fromCharCode(match.substr(1));
  });
}


This would convert a backslash followed by any numbers to the corresponding ASCII character, so convert("\\65") in JS (typed in your game that would be "\65") results in "A".

Re: Key characters
Reply #2
thanking you :)

Re: Key characters
Reply #3
@casiotone: That should probably be /\\(\d+)/g. You don't need the brackets around the \d and you need /g to replace all.

EDIT - thanks Radnen... not sure how I didn't notice that :P
  • Last Edit: May 24, 2013, 04:22:27 am by casiotone

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Key characters
Reply #4
Alpha: you mean @casiotone the other admin.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: Key characters
Reply #5

Alpha: you mean @casiotone the other admin.

Haha, thanks. I just saw the orange letters and assumed NEO. :P
  • Last Edit: May 24, 2013, 04:22:13 am by casiotone

Re: Key characters
Reply #6
I keep hitting modify instead of quote. I hate being an admin.

Quote from: alpha123
That should probably be /\\(\d+)/g. You don't need the brackets around the \d and you need /g to replace all.

whoops, yes. When I was writing it I was going to use the match group but substr on the full match was easier.

Quote from: alpha123
Who was casiotone on the old forums? I don't remember him.

:-X

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: Key characters
Reply #7

Quote from: alpha123
Who was casiotone on the old forums? I don't remember him.

:-X

What reason do you have for keeping quiet? ;)

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Key characters
Reply #8

I keep hitting modify instead of quote. I hate being an admin.


Ha, tell me about it, I made the same mistake too, luckily I never committed any of those modified messages. :P
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

  • N E O
  • [*][*][*][*][*]
  • Administrator
  • Senior Administrator
Re: Key characters
Reply #9


Quote from: alpha123
Who was casiotone on the old forums? I don't remember him.

:-X

What reason do you have for keeping quiet? ;)


I'm sure he has his reasons. :/