Aller au contenu

Photo

An easier way?


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

#1
El Condoro

El Condoro
  • Members
  • 148 messages
Noob alert!

I have a number of scripts that check a single string or integer for values and act accordingly. For example, the script below prevents a script from running if the PC is in certain areas.

 // Prevent if is during debate or in the inn
 string sArea = GetTag(GetArea(oPC));
 if ((sArea == "a_bt_int_town_hall_debate") || (sArea == "a_bt_int_inn_ground")) return;

My question is, how can a list of AND (&&) or OR  (||) conditions be better scripted? I can imagine it would get very messy if I had 6 areas that would end the script above.

Thanks

#2
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
For better readability you can make the list go vertical rather than into limbo off to the right. Something like:

if (sArea == "Area1" ||
    sArea == "Area2" ||
    sArea == "Area3" ||
    sArea == "Area4")

I think that's pretty much it as far as I know. But I'm kind of a noob myself. Good luck.

Modifié par GhostOfGod, 22 janvier 2011 - 08:13 .


#3
El Condoro

El Condoro
  • Members
  • 148 messages
I'm wondering if it's as simple as using a colon.

if (sArea == "Area1" : "Area2" : "Area3" etc. )

#4
MasterChanger

MasterChanger
  • Members
  • 686 messages
An easier way might be to include a certain string combination that your script could check for in the area tag. For example, if you wanted those areas to not be cleaned OnEnter or whatever, you might tag an area "Area2_NOCLN" or something. Then you use FindSubString(GetTag(oArea)) to check for it.

#5
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
Both GoG's and MC's suggestions are valid. Personally I use GoG's method (for easier readability as stated there). For an alternative of MC's idea, I do something like: tagging the area/object with a specific "code" (like the "*_NOCLN" idea), but instead of using the FindSubString() function, I use:

if(GetStringRight(GetTag(oArea), 5) == "NOCLN") return;

Modifié par _Knightmare_, 22 janvier 2011 - 11:37 .


#6
Shadooow

Shadooow
  • Members
  • 4 470 messages
Or you can put a variable on the area and then just check for that variable with GetLocalInt. This could be better in case you did not want to change area tags from some reason. Otherwise its the same.

#7
El Condoro

El Condoro
  • Members
  • 148 messages
I have used the area tags in other scripts already so ShaDoOoW's use of local variables on the area may be the way to go. Thanks for the tips, guys. Cheers.