Usecode: Non-boolean globals?

NOTICE: This forum is archived as read only.
Please use the Github Discussions at https://github.com/exult/exult/discussions
Forum rules
NOTICE: This forum is archived as read only.
Please use the Github Discussions at https://github.com/exult/exult/discussions
Locked
Karlos
Posts: 149
Joined: Thu May 14, 2020 1:34 pm

Usecode: Non-boolean globals?

Post 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
artaxerxes
Site Admin
Posts: 1310
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode: Non-boolean globals?

Post 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
wjp
Site Admin
Posts: 1708
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode: Non-boolean globals?

Post 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)
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode: Non-boolean globals?

Post 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.
quentin

Re: Usecode: Non-boolean globals?

Post 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
Karlos
Posts: 149
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode: Non-boolean globals?

Post 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
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode: Non-boolean globals?

Post 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.
Karlos
Posts: 149
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode: Non-boolean globals?

Post 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
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode: Non-boolean globals?

Post 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.
Karlos
Posts: 149
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode: Non-boolean globals?

Post 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
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: Usecode: Non-boolean globals?

Post 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.
Locked