Page 2 of 2

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Feb 07, 2006 9:33 am
by wjp
Can you give a code example of minimal length that shows the problem?

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Feb 07, 2006 10:16 am
by Wizardry Dragon
It's illustrated quite well in the TFL snapshot I have thusfar.

http://www.lfs.lfhost.com/tfl_forum/viewtopic.php?t=21

Just teleport to Spektran, the go north, on an island is a NPC, Chahiero. ask job, and he will have 'karma' and the debug choice, 'write karma'

Try write karma - you will see that the write will work, and you can increment karma upwards ... *but* then change the subject, and the static var returns to its default value of 0.

The well-documented code is in the /patch/src/ directory of the patch. Specifically,
/patch/src/karma/karma.uc
/patch/src/karma/related_functions/karma_functions.uc
/patch/src/npcs/related_functions/chahiero_dialog.uc

A clean 'fix' of sorts would be to have a game variables thing just as we have game flags, which would also solve my problem of how to save a karma with a savegame.

~ Wizardry Dragon

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Feb 07, 2006 12:08 pm
by wjp
Not exactly "of minimal length", is it? :-)


In any case, looks like global statics are totally broken. I fixed them, but can't commit it because the CVS server appears to be down. (I'll commit the fix as soon as possible.)

Incidentally, your comment

"used to have static vars in here but apparently they have to be in usecode.uc"

is wrong. They can be in karma.uc as long as all .uc files that use those variables are included _after_ their definition in karma.uc.
Specifically, that means the inclusion of karma_functions.uc has to be below the definition of the static karma vars.

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Feb 07, 2006 12:15 pm
by Wizardry Dragon
I speak only from my experience in what compiled and what didnt WJP, not what *should* work ^_~

Either way, Marzo has got me a good-sounding workaround that I'm trying, but if you could fix static vars that would be very helpful ^_^

As to the 'minimal length' thing - you shouldve seen how it was before I shaved it down and optimized it. My first code run is almost alway at least twice as long as the finished product ^_~

~ Wizardry Dragon

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Feb 07, 2006 12:22 pm
by wjp
> I speak only from my experience in what compiled and what didnt WJP, not what *should* work ^_~

ucc didn't complain when moving the karma vars to the top of karma.uc...

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Feb 07, 2006 12:41 pm
by Wizardry Dragon
Huh, it did for me. But a lot of things seem to go wrong for me that dont for others. UCC hates me ;_;

Didn't get any success with a workaround yet, so no working karma system. Grr ... the groundwork of this *should* be easy x_x

~ Wizardry Dragon

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Feb 07, 2006 2:21 pm
by wjp
//The heart of the karma system:
#include "karma/related_functions/karma_functions.uc";

//Overall good/evil:
static var karma;
---

You need to declare the static var(s) above the include there for it to be recognized inside karma_functions.uc.

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Feb 07, 2006 2:30 pm
by Wizardry Dragon
Eh, well I worked around it using NPC props (Marzo's suggestion), so all is good in the world.

The latest snapshot of TFL has a fully-functional (though not implemented in much depth) karma system. ^_^

http://www.lfs.lfhost.com/tfl_forum/vie ... ?p=152#152

~ Wizardry Dragon

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Feb 07, 2006 3:27 pm
by drcode
Did static vars get broken recently, or have they been bad for a while. I seem to remember problems when Marzo first tried using them, but thought those were fixed.

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Feb 07, 2006 3:28 pm
by Wizardry Dragon
Im unsure, I just know they sure didn't work when I tried them, and given that Marzo suggested the workaround, I think he may have had to use a similar workaround.

I can't speak for Marzo, though.

~ Wizardry Dragon

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Feb 07, 2006 3:30 pm
by wjp
Not sure. With the cvs server down I can't run cvs annotate to easily check.

The problem was that it was casting a sint16 into a uint16 into sint32, thereby losing the sign info. Since global statics depended on this offset being negative, they weren't working. (It was instead accessing local static number 65000+)

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Feb 07, 2006 3:37 pm
by marzo
The thing is that I never really tried using global statics (as Wizardry is), so I can't tell for sure for how long they have been broken. Normal (local) statics are working fine.

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Feb 07, 2006 3:39 pm
by Wizardry Dragon
As I am no longer, Marzo ^_~

Im using NPC props now, and it works, saves with savegames, and everything.

~ Wizardry Dragon

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Sep 25, 2007 1:05 pm
by Donfrow
Sorry to bring up a dead thread, but I does anyone know if the global statics work now?

I can declare it fine, such as

static var test;

but I can't seem to assign any value to it, but its a large possibility that I simply don't know how to assign values to it correctly so the compile is failing (I'm doing test = 1; and it's coming up with "expecting `'('' ".

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Sep 25, 2007 1:45 pm
by drcode
You should be able to assign to it inside a function. Is it possible there's something else named 'test'?

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Sep 25, 2007 2:30 pm
by Donfrow
Stupid mistake on my part which was causing the compiling error (and for the sake of avoiding any potential duplicates I renamed it to statictesting)

However, while I do not get the compiling error anymore, the value does not seem to be assigned to it, though I suspect this is due to my lack of understanding on how to actually assign a value to it.

I have my static var statictesting declared at the top of my usecode.uc which has all my #include's etc, in it.

I made a NPC that when I say a certain phrase I have:

statictesting = 50;
AVATAR.say("Statictesting value is ", statictesting);

This always returns no value on the statictesting, unless of course I do var statictesting = 50; which then works, but it is only local.

Looking up c# tutorials on how to do global variables I believe I understand the concept, but I can't actually get a working version that will compile under ucc.

Is what I'm doing correct, or is it completely off for this?

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Sep 25, 2007 4:22 pm
by marzo
Try this instead:

Code: Select all

statictesting = 50;
AVATAR.say("Statictesting value is " + statictesting);
As a suggestion: unless you need the static var to be accessible from multiple different functions, it is better (in all possible ways) to declare the static var from inside the function it is used.

Re: UCC Errors/Issues/Comments/etc.

Posted: Tue Sep 25, 2007 5:10 pm
by Donfrow
That got it working, thanks.

Thanks for the suggestion as well.