Jump to content

User-defined function not running til the end


Recommended Posts

Hi,

 

I created the following OBSE function to convert an RGB color to HSV.

 

 

 

SCN GetHSVColorFunction


array_var localArray

array_var RpGpBpArray
array_var RpGpBpArraySorted

float R
float G
float B

float Rp
float Gp
float Bp

float Cmin
float Cmax
float Delta

float H
float S
float V

short testE

;Convert RGB into HSV
Begin 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

return

End

 

 

 

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 by TheMedievalsKnights
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...