Page 1 of 1

Usecode: Non-boolean globals?

Posted: Fri Mar 07, 2003 11:06 am
by Karlos
Is it possible to define global variables in usecode that are not constants or boolean flags? For example, I'd like to have an integer to keep track of the player's "karma"; every good deed should increase this number, and every foul deed should decrease it. If it goes high enough, he may be regarded as a hero among the populace, and the interactions with various NPCs may be affected.

For that matter, are static variables supported? It didn't seem to work when I tried it.


-Karl

Re: Usecode: Non-boolean globals?

Posted: Fri Mar 07, 2003 11:08 am
by artaxerxes
use the stats, like strength, intelligence and dexterity,

Century will use those for Art, Science and Social and will also affect conversations.

Artaxerxes

Re: Usecode: Non-boolean globals?

Posted: Fri Mar 07, 2003 11:20 am
by wjp
Currently the only globals we have are booleans. It shouldn't be too hard to add integer globals, though. (It might involve adding a couple of opcodes, but that is nothing overly difficult)

Re: Usecode: Non-boolean globals?

Posted: Fri Mar 07, 2003 12:41 pm
by drcode
Say, this is something I've been wanting to do for a while, but wasn't sure if there was any interest. My thought is to use the 'static' keyword for these, and they could either be global or inside a function. In particular, a static variable inside an NPC's function would store data about that NPC. As wjp said, we'd have to add a couple opcodes in the usecode machine. And we'd also need to have a way to save/restore them with the other game files. You'll probably only be able to store integer data, at least at first.

Re: Usecode: Non-boolean globals?

Posted: Fri Mar 07, 2003 9:03 pm
by quentin
Hey I'd be interested in seeing karma inplemented too, like the system in U6, but I don't know which "sacred quest" would u be barred from for having low karma...

quentin

Re: Usecode: Non-boolean globals?

Posted: Sun Mar 09, 2003 7:45 am
by Karlos
Being able to tie the info to the NPC would be even better. For now, I'll probably use the stats as Artaxerxes suggested, then use the statics if/when that feature is added to your Usecode language.


-Karl

Re: Usecode: Non-boolean globals?

Posted: Sun Mar 09, 2003 10:54 pm
by drcode
Since each NPC has a unique function (like 0x401 for Iolo), any static variable you put in there will effectively be tied to him. I guess one problem, though, is that you wouldn't be able to use that variable (say, "karma") from other functions. I don't feel like implementing classes like C++, but here's another idea: If you have a reference to iolo in another function, you could refer to his "karma" variable using "iolo.karma". (There's a language called Verilog where you can do things like that.)

I'm almost done implementing 'static' in ucc, and I'll think about the above.

Re: Usecode: Non-boolean globals?

Posted: Mon Mar 10, 2003 5:54 am
by Karlos
Right now at least, all of the integers I'd need would affect conversations only, so that will be a great start. For example, I was going to add a bank and a banker character to my first town, so the banker would be able to keep track of how much gold the PC has in the bank at any given time.


-Karl

Re: Usecode: Non-boolean globals?

Posted: Mon Mar 10, 2003 9:35 am
by drcode
This is a good test. If only the banker's function needs to look at this variable, then it could be inside it. Otherwise, you could have globals (outside the functions), like:
static iolo_bank_account, dupre_bank_account;

Or, you should also be able to store all the accounts as a list, perhaps with an NPC# followed by that NPC's gold ammount, and write a function or two to manage the list.

I'll try some of this out in the "Island Patch" to see what works, find bugs, and provide an example. Static variables are implemented in the current CVS, but it's not tested at all yet.

Re: Usecode: Non-boolean globals?

Posted: Mon Mar 10, 2003 11:14 am
by Karlos
That's great; that'll make my job easier, I think. I suppose if I were really desperate I could have used a bunch of global Booleans to represent a binary number, but that would have gotten annoying after a while. ;-)



-Karl

Re: Usecode: Non-boolean globals?

Posted: Mon Mar 10, 2003 2:06 pm
by drcode
My feeling too. Apparently, the SI developers used a trick called the 'usecode container' where they stored numeric values, but it's a fairly klunky solution.