Will this function work?

Post » Tue Sep 02, 2014 11:54 pm

Bool Function IsDogRace(Race[] dogArray, Actor WhichActor)	;is the actor this function is being called on one of the dog races in the array? Or any race	Int dIndex = dogArray.Length	While dIndex		If WhichActor.GetRace() == dogArray[dIndex]			;is race			Return True 		Else 			dIndex -= 1		EndIf 	EndWhile	If dIndex == 0		Return False 	EndIf EndFunction

It seems possibly functional to me. The Return True WOULD stop the While loop, correct?

User avatar
Carolyne Bolt
 
Posts: 3401
Joined: Mon Jul 10, 2006 4:56 am

Post » Tue Sep 02, 2014 6:20 pm

You've got the right idea, there's just a minor issue - you need to minus from your index first thing inside the while loop.

dogArray.Length

is going to return the total number of races in the array, but the highest index will be one less than that (since array indices begin at zero). If you decrement your index right at the beginning of the while loop it will also allow you to properly check the zero index of the array before the loop exits in the final iteration (right now you're skipping over the zero index)

You're correct that using the return command will immediately exit the while loop (and the entire function). As a result, you shouldn't even need to check your index if you get past the while loop, you will just know that the actor isn't a dog and can return false right after the while loop.

User avatar
Julie Ann
 
Posts: 3383
Joined: Thu Aug 23, 2007 5:17 am

Post » Tue Sep 02, 2014 2:01 pm

The function could be a bit faster if you called GetRace once outside the while-loop and stored the returned value in a variable.

You could probably do something like this as well.

Bool Function IsDogRace(Race[] dogArray, Actor WhichActor)	;is the actor this function is being called on one of the dog races in the array? Or any race	Int dIndex = dogArray.Find(WhichActor.GetRace())	If(dIndex >= 0)		Return True)	Else		Return False	EndIfEndFunction
User avatar
Darlene DIllow
 
Posts: 3403
Joined: Fri Oct 26, 2007 5:34 am

Post » Tue Sep 02, 2014 6:45 pm


Ah, that's much better. Thank you :smile:.

And you, egocarib!
User avatar
Setal Vara
 
Posts: 3390
Joined: Thu Nov 16, 2006 1:24 pm


Return to V - Skyrim

cron