PDA

View Full Version : KotOR scripting == C++ coding?


Andrei Gijgorev
05-30-2009, 08:52 PM
When I first looked at a KotOR script, it looked exactly like C++, but now I'm not so sure anymore if that's really the case. For example, in C++ you can easily convert a float to an integer value by either of:

int Two = 2.1;
int Two = (int)2.1;
int Two = int(2.1);
int Two = static_cast<int>(2.1);

However, when trying to use one of the methods above, I get a compiling error (first method: operator = not valid for specified types, other methods: syntax error at "int"). I also encountered something else that didn't work before, but I forgot what it was. Also, it seems that the type double doesn't exist.

So, what exactly is the relationship between KorOR scripting and C++ coding? Which standard C++ methods aren't working? Is it an engine thing or a compiler problem? How can those missing methods be replaced?

stoffe
05-30-2009, 09:02 PM
So, what exactly is the relationship between KorOR scripting and C++ coding? Which standard C++ methods aren't working? Is it an engine thing or a compiler problem? How can those missing methods be replaced?

They are two completely different things. C++ is a programming language, nwscript is the scripting language of the Aurora/Odyssey game engines. Nwscript is a lot more limited in what can be done than what a full-blown programming language is, since all the scripting code is bytecode run by the game engine. The basic syntax of nwscript has some similarities to C, but the similarities end there.

All standard functions you can use in nwscript are listed in the nwscript.nss file.

As for your example there are some typecasting functions in nwscript: IntToFloat(), FloatToInt(), StringToInt(), StringToFloat() etc...

Andrei Gijgorev
05-31-2009, 07:10 AM
Well, I thought the similarities wouldn't end at perfunctory syntax resemblances, since even the #include directive is present and I can define my own structs, but apparently I was wrong there.
I knew about nwscript.nss, but I thought there were only in-game functions specified and not basic things like typecasting.
Anyway, things are a lot clearer now, thank you.
I was just about going to suggest adding a passage about similarites to C / C++ programming to this tutorial (http://www.lucasforums.com/showthread.php?t=143390) when I stumbled across a link to nwnlexicon.com there. Maybe post that link to a few other tutorials? I think it's much more useful than nwscript.nss.

stoffe
05-31-2009, 03:45 PM
I was just about going to suggest adding a passage about similarites to C / C++ programming to this tutorial (http://www.lucasforums.com/showthread.php?t=143390) when I stumbled across a link to nwnlexicon.com there. Maybe post that link to a few other tutorials? I think it's much more useful than nwscript.nss.

The Lexicon is indeed a handy reference, but it can be somewhat confusing to people who are new to writing nwscript for the KOTOR games since it covers the Neverwinter Nights version of NWScript. While they're essentially the same there are some things that are handled differently, and some functions that exist in one game but not the other. The most major difference off the top of my head is how local game variables are handled.