Help on an if Statement

Post » Sun Nov 18, 2012 10:03 pm

Hello
I would like to Execute my function if player level is between 17 and 25.
here is my function

Spoiler
Scriptname GP_MyFunctionScript Function MyFunction() Global	If Game.GetPlayer().GetLevel(); over here i want to say "between 17 & 25", so whats the code for typing "between 17 & 25" ?		;Do Something In here	EndIf	EndFunction
User avatar
jessica breen
 
Posts: 3524
Joined: Thu Aug 03, 2006 1:04 am

Post » Mon Nov 19, 2012 7:07 am

This should work :)

Scriptname GP_MyFunctionScript Function MyFunction() Global	If Game.GetPlayer().GetLevel() <= 25 && Game.GetPlayer().GetLevel() >= 17		;Do Something In here	EndIf	EndFunction

That's the aim anyway.
User avatar
Claire
 
Posts: 3329
Joined: Tue Oct 24, 2006 4:01 pm

Post » Mon Nov 19, 2012 10:41 am

thx mate
I will try it now and let you know !
User avatar
Tyrone Haywood
 
Posts: 3472
Joined: Sun Apr 29, 2007 7:10 am

Post » Mon Nov 19, 2012 6:51 am

thx mate
I will try it now and let you know !

Using && (usually by putting brackets around conditions like (game.blahh() == something) && (game.blahh() == somethingelse)

Is the way I do it.

That method of checking multiple things was my eureka moment in ck scripting :)
User avatar
Ebony Lawson
 
Posts: 3504
Joined: Fri Feb 16, 2007 11:00 am

Post » Mon Nov 19, 2012 6:06 am

Ands (&&) and Ors (II) will go a long way when you have to check multiple things. Just remember not to overload the if with Ands or Ors, or it can become confusing to debug, in which case it is better to nest the if. Here is a very abstract example:
;DO NOT DO THIS IF YOU ARE HAVING ISSUES UNDERSTANDINGif (this.thing == this.value || this.thing == value) && (this.thing2 < value || (this.thing3 > value && this.thing4 < value))   ;something is done hereendif;Better way to do this, for your clarityif(this.thing == value || this.thing == value)  if this.thing2 < value	  ;same something done here  elseif (this.thing3 > value && this.thing4 < value)	  ;same something done here  else	  ;do nothing  endif;if there are any other checks you are doing linked to the original check, they go here.endif

Sure this will introduce repeated if statements, and will be more inefficient, but it is more important to be easy to understand since you are still learning the ropes of scripting.
User avatar
Jonathan Montero
 
Posts: 3487
Joined: Tue Aug 14, 2007 3:22 am

Post » Sun Nov 18, 2012 9:49 pm

I'd just like to suggest a couple of changes to that suggested script:
Spoiler
Scriptname GP_MyFunctionScriptActor Property PlayerRef AutoFunction MyFunction()	Int PlayerLevel = PlayerRef.GetLevel()	If PlayerLevel <= 25 && PlayerLevel >= 17		;Do Something In here	EndIfEndFunction
Because the player reference never changes, and the player's level will not change during a single execution, I've only requested each of these values once.

In that example I've changed MyFunction to a non-global function, mainly because I imagine you'll probably be checking this on an object and making it a non-global function allows you to make use of the PlayerRef property, which can be auto-filled in the Creation Kit to point to the player.

If this function doesn't need to be run on an object, then it can be left global and I'd recommend using this instead:
Spoiler
Scriptname GP_MyFunctionScriptFunction MyFunction() Global	Actor PlayerRef = Game.GetPlayer()	Int PlayerLevel = PlayerRef.GetLevel()	If PlayerLevel <= 25 && PlayerLevel >= 17		;Do Something In here	EndIfEndFunction

Cipscis
User avatar
keri seymour
 
Posts: 3361
Joined: Thu Oct 19, 2006 4:09 am

Post » Mon Nov 19, 2012 12:04 am

Well thank you all for your reply, Actually I am Saving all MyFunction(s) on a separate File called GP_MyFunctionScrips
Then I am calling them from a different Script file in any Scdript file in the game.
One of the Script file that I will be calling any of my functions for instance, like this Script below for Example As Justin Suggested and it worked fine !

Script Where My Functions Are:
Spoiler
Scriptname GP_MyFunctionScriptFunction MyFunction() Global If Game.GetPlayer().GetLevel(); over here i want to say "between 17 & 25", so whats the code for typing "between 17 & 25" ?  ;Do Something In here EndIfEndFunction

Script where I will be Calling My function:
Spoiler
ScriptName GP_Test Extends ActorImport GP_myfunctionScriptActor Property PlayerRef Auto  Auto State AutoState        Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)    If akAggressor == PlayerRef	Debug.Notification("Level " + GetLevel())	EndIf	GoToState("")EndEventEndStateEvent OnDeath(Actor akKiller)    If akKiller == PlayerREF	MyFunction()	EndIfEndEvent
User avatar
Rachael
 
Posts: 3412
Joined: Sat Feb 17, 2007 2:10 pm


Return to V - Skyrim