🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Character literals and uint8

Started by
3 comments, last by Deyja 18 years, 10 months ago
If I create a uint8, and try to assign a character literal, I get an error. For example:

uint8 fill;
fill = '0';
I get the following error: "Error : Expected expression value" This isn't a critical problem (I'm using setfill, i.e. "cout << std.setfill('0')"), since I can substitute the ASCII equivalent in hex, decimal, whatever. I'm just curious if it should be allowed.
Advertisement
It's funny when people mistake questions about AngelScript syntax for questions about C++. [wink] (As a moderator I can see deleted posts.)

Single character literals are not implemented in the AngelScript syntax yet. I haven't decided if I will do so either.

Currently I suggest that you expose a function like 'uint8 ascii(string∈)' that returns the ascii code for the first character in the string, or use numeric constants.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Quote: Original post by WitchLord
It's funny when people mistake questions about AngelScript syntax for questions about C++. [wink] (As a moderator I can see deleted posts.)

I don't understand exactly what you mean [looksaround]. Granted, AngelScript is not C++, and with such close syntax, I guess I went with the same syntax.

Quote: Original post by WitchLordSingle character literals are not implemented in the AngelScript syntax yet. I haven't decided if I will do so either.

I'm no compiler expert, and what you have so far is great. There's no great need for them (we can make do with numeric constants), but I wasn't sure if it was available. There's no mention in the ScriptWriter's manual, but I was hoping... [grin]
I'm sorry about the confusion, I should have explained better. Just before my answer to your question someone else answered. That person mistook your question for being about C++, and answered it as such. However, he (or she) realized his own mistake and deleted the post before anyone could see it, except for those of us who are moderators. [wink]

Character literals wouldn't be difficult to implement, I just can't decide wether I want them or not. I've come to know that in C/C++ character literals are really interpreted by the preprocessor, so the underlying compiler really don't understand them. AngelScript could support them in the same way, and in fact, with Deyja's preprocessor it already does.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Indeed it does. I ran across this same problem some time back, and asked WL about it. After a bit of research, I discovered that in C++ the preprocessor handles it, so I added it to mine. It does it in the simplest way imaginable. When it detects a ' character, it assumes the next character is the one to encode, and the one after it is another '. It does absolutly no error checking, and if you do something like 'lotsofcharacters' you will get some rather hard to decode error in angelscript. It does support escapes, but only newline, carriage return, and tab.

This topic is closed to new replies.

Advertisement