Negative variables

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
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Negative variables

Post by Donfrow »

I am running into an issue when trying to use some variables with negative numbers. I'm not quite sure what I'm missing but I cannot seem to get the variables to have a value with a negative number. The reason for this is what I to pass a NPC number, which from my understanding will always be negative.

On the most basic level, I have an egg that does this:

var npc = 123;
AVATAR.say("The NPC is ", npc);

Which, in game results in the Avatar saying "The NPC is 123".

However, if I set it as following:

var npc = -123;
AVATAR.say("The NPC is ", npc);

This results in the Avatar saying "The NPC is ". It seems it does not like me assigning the negative number and I'm not sure why. I've also tried var npc = (-123).

The reason I want to do this is so I can use UI_si_path_run_usecode with the NPC variable, ie UI_si_path_run_usecode(npc, [x, y, z], SCRIPTED, test, test, true), where the npc variable needs to be negative. I do not want to hard code it as UI_si_path_run_usecode(-123, [x, y, z], SCRIPTED, test, test, true) as it could be 1 of 4 NPC's determined by random number.

Am I missing something obvious with this? How can I give a variable a negative number so it can be used in intrinsics that utilize negative numbers?

Thanks
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Negative variables

Post by Knight Captain »

AVATAR.say("@The NPC is ", npc, ".@");

I have code for this at home.

SI does the negative flip in two ways.
There's an invert value function in Usecode.
Number * -1 also works.
I believe Q&I mod has something that adds or subtracts 1024.

The alpha mod I sent you has this in the wisp debug menu as well.
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Negative variables

Post by Donfrow »

Could you re-send me the alpha mod? I saw the email with it when you sent it originally and had intended to take a look but now I can't find it for some reason, which is odd as I rarely ever delete any messages and it's not even in my deleted folder.

I had tried the * -1 before posting as well but it was the same result where it was always just a blank value. I know the math is working as I can do the test without negative numbers:

var test = 1*2;
AVATAR.say("The number is ", test);

This will result in "The number is 2" as expected.

If I do

var test = 1*-2
AVATAR.say("The number is ", test);

This will result in "The number is ", as in my first example.
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Negative variables

Post by Knight Captain »

The email is over to you along with the latest wisp debug mode menu.

Here's the bit of code that may help:
case "NPC details" :
say("@Who would 'you' like information about?@");
npc = UI_input_numeric_value(1, 355, 1, 1);
// The actual NPC number is a negative value, so here we take the positive input,
// subtract it from the same to get zero, then subtract it again to get the same
// value as a negative number.
npc = ((npc - npc) - npc);
// Show that NPC's name for confirmation.
name = (npc->get_npc_name());
say("@That is '", name, "'.@");
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Negative variables

Post by Knight Captain »

Looks like get_npc_number may also help you here.
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Negative variables

Post by Donfrow »

It seems to be that as soon as my variable is a negative, it floats away into the ether, at least as far as it goes in a say block. For good measure I've updated to the latest release and latest usecode compiler but it makes no difference.

Thanks for the mod. I tried it and made a slight modification and it's the same behavour I'm getting. From your file I added the following under the NPC details:

npc = ((npc - npc) - npc);
name = (npc->get_npc_name());
say("The NPC number is ", npc); --- added this line
say("@That is '", name, "'.@");

It is pulling the name back so there's something assigned to that variable "npc "other wise the name wouldn't come back (which it is), yet it never says anything when you output NPC, as long as it's negative.

Is this just something that you can't do maybe? The main reason I wanted to bark out a NPC number that is negative is for testing purposes to ensure it's the proper NPC being returned and passed to other functions.
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Negative variables

Post by Knight Captain »

I think the problem is you're not escaping the string. So this:
say("The NPC number is ", npc);
Should be more like this:
say("@The NPC number is ", npc, ".@");

I tend to use Notepad++ along with the included C# language coloring since it helps with when you're in a string and outside it (in code again).
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Negative variables

Post by Donfrow »

I'm by no means an expert but I think as long as there is a valid item at the end of the say, it should go out, and the quote at the end would only be for appearances? It works without issue with positive numbers. Regardless, it seems not to be the case as to what my problem is:

var test = -25;
AVATAR.say("@Trying this now ", test, ".@");

Still results in:

"Trying this now ."

Where as

var test = 25;
AVATAR.say("@Trying this now ", test, ".@");

results in what I would expect

"Trying this now 25."

Not the end of the world as you've shown me it's at least working even if the output is blank but makes things difficult when my other coding isn't working and I want to make sure the NPC reference is correct.
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Negative variables

Post by Knight Captain »

Check it against the magic_leggings.uc file I sent you, which is in the mod I sent over (set flag 2).

I don't use the AVATAR.say at all, and neither does SI Fixes. I don't know if that is part of the issue or not though. Just plain say or partyUtters.

So you just want Usecode that allows different NPCs to perform the same set of scripted actions on screen?
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Negative variables

Post by Donfrow »

I took your magic_leggings.uc and tried it out by adding an extra line of say, but same thing.

npc = ((npc - npc) - npc);
// Get that NPC's name for confirmation.
name = (npc->get_npc_name());
say("@The NPC number is ", npc, "@.");
say("@That is '", name, "'.@");

But it's the same thing where "npc" is always nothing.

I should have clarified, AVATAR.say is a regular say where AVATAR = -356, so it's not different than (-356).say.

You are correct why I wanted to use it. What I was doing wasn't working so I wanted to make sure it was getting the proper NPC number, but then I ran into this where it doesn't seem to be able to say what that value is. I eventually gave up on it and just used a single NPC for what I wanted it for, but I could easily see myself wanting to do something similar again at some point.
Knight Captain
Posts: 1219
Joined: Thu May 14, 2020 1:34 pm

Re: Negative variables

Post by Knight Captain »

There's a few ways, I'd imagine.

You can select all non-party on-screen, or do an array of certain NPCs with a delay between each. I'm not as up on it yet, but I'd suggest something like:

for (each_npc in npc_array with index to max)
script here
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Negative variables

Post by Donfrow »

That's a good idea which I may have to do in the future for something but don't think it would have worked for this. What I should have done is create a new NPC object and move it and then delete it, as it's really just meant to show someone "walking" and look like it's a busy area.

For now, it's accomplished by changing the shape of a single NPC (only 1 is ever on screen at once, so not as big of an issue) and then if the egg is triggered again I do the same thing, but randomly set the NPC shape to another shape.

It works, and makes my teleport room look a bit busier, but now this negative variable is eating away at me. Hopefully someone knows what's going on with it and it's some simple mistake on my part, as I definitely think I would have use for it in debugging things later on.

Thanks for your help with this one.
Locked