Comparing a local race string
#1
Posté 22 août 2011 - 08:08
if ( GetRacialType(oPC) == RACIAL_TYPE_DWARF )
so what is the proper syntax for inserting the sRace variable in this if statement? (The string has been previously defined, of course).
Thanks!
#2
Posté 22 août 2011 - 08:31
if(sRace == RACIAL_TYPE_DWARF)
But is it what you're trying to do?
Kato
Modifié par Kato_Yang, 22 août 2011 - 08:32 .
#3
Posté 22 août 2011 - 08:46
string sRace = GetRacialType(oPC);
if (sRace == RACIAL_TYPE_DWARF)
{
// Do Dwarf Stuff
}
else if (sRace == RACIAL_TYPE_ELF)
{
// Do Elf Stuff
}
else if ....
#4
Posté 23 août 2011 - 02:46
The NPC would have a local variable of sRace. What I want is a conditional that if sRace = PC race then one action is taken, and if they are not equal then a different action is taken.
So what I'm trying to get at is
if ( GetRacialType(oPC) == RACIAL_TYPE_sRace )
Modifié par Badwater, 23 août 2011 - 03:59 .
#5
Posté 23 août 2011 - 05:44
GetRacialType(oPC) returns an int so you can't compare it with string. You need a function that will convert your string to int, ie:
int MyRace(string sRace)
{
if sRace == "dwarf" return RACIAL_TYPE_DWARF;
else if sRace == "elf" return RACIAL_TYPE_ELF;
...
or you could just set sRace on PC in OnEnter event and than compare strings.
#6
Posté 23 août 2011 - 06:01
If I'm reading the above correctly, then I'm still not at a place where I have a conditional in conversation where the PC's race compares to the NPCs race or it doesn't. I guess it really doesn't matter whether it's comparing an integer or a string, I just want a local variable on the NPC where I can simply compare and the conversation goes in one direction or it goes in the other.
#7
Posté 23 août 2011 - 06:12
int iNPCRace = MyRace(GetLocalString(oNPC, "NameOfVar")); if(GetRacialType(oPC) == iNPCRace)
Modifié par Alex Warren, 23 août 2011 - 06:15 .
#8
Posté 23 août 2011 - 06:38
#9
Posté 23 août 2011 - 06:57
int StartingConditional()
{
return (GetRacialType (GetPCSpeaker() ) == GetRacialType (GetLastSpeaker() ) );
}
#10
Posté 23 août 2011 - 01:58
RACIAL_TYPE_* is a integer.
Even if your sRace is "RACIAL_TYPE_DWARF" it will not match RACIAL_TYPE_DWARF that is outside quotation ("") marks, because the engine treats it as a number.
If you compare wrong types of variables the script shouldn't even compile.
if(sRace == "asdf") {}
#11
Posté 23 août 2011 - 03:48
Badwater wrote...
I have different racial towns and I want to use a common conversation that will do two different things based on whether the NPC is the same race as the PC. I did not want to create a special script to handle this, as I already have the scripts to perform the actions I have in mind.
The NPC would have a local variable of sRace. What I want is a conditional that if sRace = PC race then one action is taken, and if they are not equal then a different action is taken.
So what I'm trying to get at is
if ( GetRacialType(oPC) == RACIAL_TYPE_sRace )
You might just grab the NPC racial type:
if ( GetRacialType(oPC) == GetRacialType(OBJECT_SELF) ) ...
<...and stealing four>
Modifié par Rolo Kipp, 23 août 2011 - 03:51 .
#12
Posté 23 août 2011 - 09:58
#13
Posté 23 août 2011 - 10:32
If he just wants to compare PCs race to NPCs, why would you even mess with strings? Wouldn't
{
if ( GetRacialType(oPC) == GetRacialType(OBJECT_SELF) ) return TRUE;
return FALSE;
}
give him the conditional he wants without worrying about a variable on the NPC or pulling a string out of the 2da?
Not capping or anything. Really want to know.
<...but interested>
#14
Posté 23 août 2011 - 11:44
#15
Posté 23 août 2011 - 11:47
Ahhh, thank you. Thought I was missing something... again :-P
<...er, persp... *sweat* from his brow>
#16
Posté 24 août 2011 - 09:12
Thanks for your answer, Rolo - that's the one that has the most options for me. But again, thanks to all of you, because I learned something today....*South Park segue*
#17
Posté 24 août 2011 - 04:19
NP :-) That's how I learn, too
I am one of the oldest scripters on this board (well, on the old Interplay board...), but, thanks to years wandering in the desert, one of the greenest noobs :-P An awkward dichotomy.
Still, I'm having a lot of fun =) And I like Lightfoot8's algo for something else I was frustrated by... so, yeah, I learned something too.
@Lightfoot8 Is "return (boolean condition);" more efficient cpu-wise than "if (bCondition) return TRUE; return FALSE;"? Or, to be clearer, do they compile differently? Does the second method add an extra branch?
<...still young enough to blush>
Modifié par Rolo Kipp, 24 août 2011 - 04:20 .
#18
Posté 24 août 2011 - 10:22
No they do not compile to the same thing.
Yes it adds another branch. along with having to move the value of the TRUE/FALSE constant onto the stack and move it around.
EDIT: you can always look at the compiled code for your scripts with nwnexplorer.
If you want to know what all the codes mean they are listed at the following off site link.
http://www.nynaeve.n...tation/ncs.html
Modifié par Lightfoot8, 24 août 2011 - 10:24 .
#19
Posté 24 août 2011 - 10:49
Thank you! It is true in C, but I've been told over and over that (though based off C) NWScript is *not* C. :-/Lightfoot8 wrote...
Yes it is more efficent CPU wize.
No they do not compile to the same thing.
Yes it adds another branch. along with having to move the value of the TRUE/FALSE constant onto the stack and move it around.
(Mostly when we were arguing with Don Moar for arrays...)
An old fox like me? When cool cats like you are so willing (and effective!) at helping? ;-)EDIT: you can always look at the compiled code for your scripts with nwnexplorer.
(translation: Didn't know that :-) Cool. Sometimes I get on a real OCD, minimalist coding kick... I'll use that then)
<...and slips out of the coop)
Modifié par Rolo Kipp, 24 août 2011 - 10:50 .





Retour en haut






