TheMedievalsKnights Posted May 5, 2020 Share Posted May 5, 2020 (edited) Hi, I created the following OBSE function to convert an RGB color to HSV. SCN GetHSVColorFunctionarray_var localArrayarray_var RpGpBpArrayarray_var RpGpBpArraySortedfloat Rfloat Gfloat Bfloat Rpfloat Gpfloat Bpfloat Cminfloat Cmaxfloat Deltafloat Hfloat Sfloat Vshort testE;Convert RGB into HSVBegin Function { R, G, B }: let localArray := ar_Construct Array let RpGpBpArray := ar_Construct Array let RpGpBpArraySorted := ar_Construct Array ;Scale back RGB values between 0 and 1 set Rp to R/255 set Gp to G/255 set Bp to B/255 ;Assign rescaled values to array let RpGpBpArray[0] := Rp let RpGpBpArray[1] := Gp let RpGpBpArray[2] := Bp ;Sort the array in order to get the max and min let RpGpBpArraySorted := ar_Sort RpGpBpArray 0 let Cmin := RpGpBpArraySorted[0] let Cmax := RpGpBpArraySorted[2] set Delta to (Cmax - Cmin) ;Hue calculation print "Began" if Delta == 0: set H to 0 set testE to 1 elseif Cmax == Rp: set H to (Gp - Bp)/Delta set testE to 2 elseif Cmax == Gp: set H to (Bp - Rp)/Delta + 2 set testE to 3 elseif Cmax == Bp: set H to (Rp - Gp)/Delta + 4 set testE to 4 endif print "Ended" print $testE set H to 60*H if h < 0: set H to H + 360 endif ;Saturation calculation if Delta == 0: set S to 0 else: set S to Delta/Cmax endif ;Value calculation set V to Cmax let localArray[0] := H let localArray[1] := S let localArray[2] := V SetFunctionValue localArray printc H printc S printc V returnEnd To test my function, I created a quest, where stage 20 has a result script that calls the function, (with arguments 100 200 50) However, when I try my function ingame with setstage myquest 20, it seems my function does not go past "hue calculation" since "Began" gets printed in the console but not "Ended". Edited May 5, 2020 by TheMedievalsKnights Link to comment Share on other sites More sharing options...
TheMedievalsKnights Posted May 5, 2020 Author Share Posted May 5, 2020 Ok rookie error I guess or bad python reflex, you don't need semi-column in your code Link to comment Share on other sites More sharing options...
Recommended Posts