Can anyone explain this code snippet?

Post » Thu Jun 21, 2012 2:16 pm

I was studying the scripts that come with the CreationKit, and came across the script FireFly.psc, which apparently controls the behavior of fireflies.

In this script I found a snippet of code commented (line 208):

; Helper method to indicate whether the player has the ingredientbool Function ShouldFlockAroundPlayer(); if (Game.GetPlayer().GetDistance(Spawner) > fRadius);  return false; endIf; return (Game.GetPlayer().GetItemCount(IngredientType) > 0)return falseendFunction

This part, which is commented, seems to be a very interesting feature, from what I saw in the code, this section should verify if the player has any ingredient that attracts the firefly, if the player an ingredient that attracts the firefly, it should follow him.

Can someone explain to me, or have any idea why it is commented out? The developer didn't had enough time to implement, and commented the code?
User avatar
Michelle Chau
 
Posts: 3308
Joined: Sat Aug 26, 2006 4:24 am

Post » Thu Jun 21, 2012 1:05 pm

I was studying the scripts that come with the CreationKit, and came across the script FireFly.psc, which apparently controls the behavior of fireflies.

In this script I found a snippet of code commented (line 208):

; Helper method to indicate whether the player has the ingredientbool Function ShouldFlockAroundPlayer(); if (Game.GetPlayer().GetDistance(Spawner) > fRadius);  return false; endIf; return (Game.GetPlayer().GetItemCount(IngredientType) > 0)return falseendFunction

This part, which is commented, seems to be a very interesting feature, from what I saw in the code, this section should verify if the player has any ingredient that attracts the firefly, if the player an ingredient that attracts the firefly, it should follow him.

Can someone explain to me, or have any idea why it is commented out? The developer didn't had enough time to implement, and commented the code?

Your interpretation seems accurate. The function, if uncommented would return the item count for that ingredient. Since it's defined as a BOOL,that would make it not 0. I'm not sure how Papyrus would handle a number greater than 1 as a bool. As to why it was commented out... who knows ;) I've seen lots of crazy code.
User avatar
neen
 
Posts: 3517
Joined: Sun Nov 26, 2006 1:19 pm

Post » Thu Jun 21, 2012 10:31 pm

Even more interesting is that the code that makes fireflies follow the player has been developed, but due to this commented code, it will never be executed (because ShouldFlockAroundPlayer always returns false):
; Utility method, makes a Firefly flock to a random point around the playerFunction FlockToPlayer()    ; Switch state; ;     Debug.TraceConditional("Firefly " + self + " going to state FollowingPlayer", bCritterDebug)    gotoState("FollowingPlayer")    ; Pick a random point around the player    float ftargetX = Game.GetPlayer().X + RandomFloat(-fFlockPlayerXYDist, fFlockPlayerXYDist)    float ftargetY = Game.GetPlayer().Y + RandomFloat(-fFlockPlayerXYDist, fFlockPlayerXYDist)    float ftargetZ = Game.GetPlayer().Z + RandomFloat(fFlockPlayerZDistMin, fFlockPlayerZDistMax)    float ftargetAngleZ = RandomFloat(-180, 180)    float ftargetAngleX = RandomFloat(-20, 20)    float fpathCurve = RandomFloat(fPathCurveMean - fPathCurveVariance, fPathCurveMean + fPathCurveVariance)    ; Travel to it    TranslateTo(ftargetX, ftargetY, ftargetZ, ftargetAngleX, 0.0, ftargetAngleZ, fFlockTranslationSpeed, fMaxRotationSpeed)endFunction
User avatar
Jennifer May
 
Posts: 3376
Joined: Thu Aug 16, 2007 3:51 pm

Post » Thu Jun 21, 2012 9:20 am

Your interpretation seems accurate. The function, if uncommented would return the item count for that ingredient. Since it's defined as a BOOL,that would make it not 0. I'm not sure how Papyrus would handle a number greater than 1 as a bool. As to why it was commented out... who knows :wink: I've seen lots of crazy code.

it's not returning the item count. it's returning whether or not the item count is greater than 0 (true or false)
User avatar
Cedric Pearson
 
Posts: 3487
Joined: Fri Sep 28, 2007 9:39 pm

Post » Thu Jun 21, 2012 1:41 pm

I say someone needs to uncomment this svcker and make it happen :D
User avatar
maddison
 
Posts: 3498
Joined: Sat Mar 10, 2007 9:22 pm


Return to V - Skyrim