Aller au contenu

Photo

Quick question on local variables and scripts


  • Veuillez vous connecter pour répondre
37 réponses à ce sujet

#26
Rolo Kipp

Rolo Kipp
  • Members
  • 2 791 messages
<looks alarmed...>

Don't give up!

(because I'm working with the Travel Builder system, and it sounds like your problem - or, more importantly, your solution - will be pertinent to me ;-)

First, verify (in game) that the variable is/is not set. I am suspecting it is somehow set. Perhaps it is set on another object (or supposed to be) but got set on this one... Like WhiZard said.

At any rate, put in traps (like LoWs is doing with *his* problem :-) in different places to try and catch when it is being set (if that's the case).

<...and trapped>

Modifié par Rolo Kipp, 27 août 2011 - 10:08 .


#27
Alassirana

Alassirana
  • Members
  • 55 messages
I'm still fairly new to a lot of this...how do I put in traps to find these things?

#28
WhiZard

WhiZard
  • Members
  • 1 204 messages

Alassirana wrote...

I'm still fairly new to a lot of this...how do I put in traps to find these things?



If you are testing this singleplayer, you can use GetFirstPC() in signalling commands to make sure your character is reported the details.

Example
if(iInteger == TRUE)
  {
 SendMessageToPC(GetFirstPC(), "iInteger is returning TRUE");
  }

#29
Rolo Kipp

Rolo Kipp
  • Members
  • 2 791 messages
<looks contrite...>

Alassirana wrote...

I'm still fairly new to a lot of this...how do I put in traps to find these things?

Sorry, didn't mean to be obscure.

What I meant is to put in some debugging printouts in places likely to affect the PButton item.

In those places put a couple lines of code in there like:

    if (iFokua != TRUE) ActionSpeakString("Fokua is NOT DEFINED", TALKVOLUME_SHOUT);
    if (iFokua == TRUE) ActionSpeakString("Fokua is SET! Drat!!!!!!! I'm in so-and-so function/script", TALKVOLUME_SHOUT);

Then test the mod and see where it gets set.

<...but it's probably a sham>

#30
Alassirana

Alassirana
  • Members
  • 55 messages
I had an idea while looking through things...since I'm dealing with a single item with several local variables on it, could that be the problem there? Should I be using an array, rather than a local int on the item?

#31
Rolo Kipp

Rolo Kipp
  • Members
  • 2 791 messages
<Keeps a sharp eye peeled...>

What he said :-) Though I would explicitly state in each trap whether it was set or not.
And, at the very least, I would first put traps in your Area's OnEnter.

<...for errant bits and pieces>

#32
Rolo Kipp

Rolo Kipp
  • Members
  • 2 791 messages
 <shakes his head sadly...>

Sorry, no arrays in NWScript. And now that I've read Skywing's blog, I understand why :-/ R.I.P.
Unfortunately, that implies that pseudo-arrays would be unwieldy and inefficient. (Don't know that for sure, Funky might :-)

I would stick with integers. In fact, I *am* sticking with integers, but my travel is complicated even more-so as there are 8 versions of all the main areas... Yikes.

<...and holds his big, ugly, floppy hat over his shrivelled excuse for a heart>

#33
Alassirana

Alassirana
  • Members
  • 55 messages
Um, according to the nwn lexicon (v 1.69) there is a function entitled: GetLocalArrayInt And it seems to be saying that I am actually trying to get an array here...I just don't understand it all.

#34
Alassirana

Alassirana
  • Members
  • 55 messages
And, of course, it is paired by it's opposite: SetLocalArrayInt.

#35
Rolo Kipp

Rolo Kipp
  • Members
  • 2 791 messages
<biting down hard...>

Alassirana wrote...

Um, according to the nwn lexicon (v 1.69) there is a function entitled: GetLocalArrayInt And it seems to be saying that I am actually trying to get an array here...I just don't understand it all.


Yes, but that is a pseudo array. Using a naming convention to make it more convenient to manage variables, basically.

Although this is hardly an array, it can be accessed like one, and can even be
looped through. It works by creating a new local integer object on whatever
object you passed in through the parameters. This LocalInt is called sVarName +
nVarNum, so in otherwords if I called the following:...

IOW, it's using a function to name and manage variables... adding another layer of work for the script to do.

<... to see if it's gold>

#36
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Actually I think your problem is much more simple. And I think Rolo mentioned it. The line in the conversation  should only show up if the variable is on the item right? Like if you've been to disneyland the variable gets set on your item and then when the conversation pops up you should be able to see the "disneyland" line? The highlighted TRUE and FALSE below need to be switched (I already switched them in the script).


int StartingConditional()
{
    // Get the PC who is involved in this conversation
    object oPC = GetPCSpeaker();
    object oPButton = GetItemPossessedBy(oPC, "panicbutton");
    int iFokual = GetLocalInt(oPButton, "Fokual");
    if (iFokual == TRUE)
        return TRUE;

    // If we make it this far, we have passed all tests.
    return FALSE;
}


For the life of me I could not wrap my head around starting conditionals for the longest time. And it wasn't until someone scripted one a certian way that I was able to understand them. Now I know how to do them a bit different but this way made it easy for me. Maybe it will help you:


int StartingConditional()
{
    if (some condition == whatever)
    {
        return TRUE;//Show this line in conversation
    }

    else
    {
        return FALSE;//Don't show this line in conversation
    }
}

Modifié par GhostOfGod, 28 août 2011 - 03:14 .


#37
Alassirana

Alassirana
  • Members
  • 55 messages
That fixed it...thanks.

#38
Rolo Kipp

Rolo Kipp
  • Members
  • 2 791 messages
<blushes...>

GhostOfGod wrote...

Actually I think your problem is much more simple. And I think Rolo mentioned it. The line in the conversation  should only show up if the variable is on the item right? Like if you've been to disneyland the variable gets set on your item and then when the conversation pops up you should be able to see the "disneyland" line? The highlighted TRUE and FALSE below need to be switched (I already switched them in the script).

You ever scan something and your mind (because it *knows* what goes where) let you see something that *isn't* what was writtien?

How did I miss that? I *know* that's a common fault (of mine!) and I specifically scan for that (in my own debugging)... But this time I just skipped over it...

I'm getting old :-(

<...or *tries* to>