Spherical forums

Sphere Development => Sphere Support => Script Support => Topic started by: Harry Bo21 on May 23, 2013, 12:19:55 pm

Title: Key characters
Post by: Harry Bo21 on May 23, 2013, 12:19:55 pm
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?
Title: Re: Key characters
Post by: casiotone on May 23, 2013, 12:31:02 pm
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".
Title: Re: Key characters
Post by: Harry Bo21 on May 23, 2013, 08:42:58 pm
thanking you :)
Title: Re: Key characters
Post by: alpha123 on May 23, 2013, 10:10:22 pm
@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
Title: Re: Key characters
Post by: Radnen on May 23, 2013, 11:14:54 pm
Alpha: you mean @casiotone the other admin.
Title: Re: Key characters
Post by: alpha123 on May 23, 2013, 11:19:43 pm

Alpha: you mean @casiotone the other admin.

Haha, thanks. I just saw the orange letters and assumed NEO. :P
Title: Re: Key characters
Post by: casiotone on May 24, 2013, 04:22:57 am
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
Title: Re: Key characters
Post by: DaVince on May 24, 2013, 09:26:39 am

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

:-X

What reason do you have for keeping quiet? ;)
Title: Re: Key characters
Post by: Radnen on May 24, 2013, 12:29:44 pm

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
Title: Re: Key characters
Post by: N E O on May 24, 2013, 01:19:51 pm


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. :/