相关文章推荐
I am working on a project and I am taking 2 text+ nodes, subtracting the value of one from the other and assigning it to a 3rd text+ node. I got the subtraction part working, but ....

It turns out that if the result is a negative number I have to set it to 0 (Zero). According to the documentation I could find, the following statement should work.

iif ( (Text(Points_Data.StyledText.Value - Penalties_Data.StyledText.Value) > 0), (Text(Points_Data.StyledText.Value - Penalties_Data.StyledText.Value)), (Text(0)) )

I have tried it with if instead of iif as well, but no joy. I am just not familiar with lua. Most of my experience in programming lies in much higher level languages like Visual Basic, PHP/MySQL, Cobol, etc.

If I was doing this in BASIC I would have written it like this;

If Points - Penalties > 0
Total_Points = Points - Penalties
Else
Total_Points = 0
End

( Sorry, the forum is stripping the spaces from the code example )

Truthfully I am just lost when I try and study the LUA manual. This is the last thing I have to figure out to make my client happy. Any help would be greatly appreciated.
-
➤ DVR 18.02 Studio
CPU: Ryzen 9 3900XT
MB: Gigabyte B550 Vision D-P
➤ WiFi 6 , BT 5 , 2.5 Gb Ethernet
RAM: 64 GB
GPU: Sapphire Nitro+ 6700 XT 12 GB
PSU: 850W 80+ Gold
OS: Win 10 Pro 21H1 Build 19043.1202
The text() turns everything into a string so the Text+ tool can display it as such. But you can't subtract two strings like numbers. So just get rid of the Text() functions inside the iif.
Try something like this:

Text(iif(Text1.StyledText.Value-Text2.StyledText.Value < 0, 0, Text1.StyledText.Value-Text2.StyledText.Value))

Code: Select all
{
Tools = ordered() {
Text2 = TextPlus {
NameSet = true,
Inputs = {
GlobalIn = Input { Value = 1, },
Width = Input { Value = 1920, },
Height = Input { Value = 1080, },
["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
StyledText = Input {
Value = "-13",
Expression = "Text(-time+10)",
},
Font = Input { Value = "Open Sans", },
Style = Input { Value = "Bold", },
VerticalJustificationNew = Input { Value = 3, },
HorizontalJustificationNew = Input { Value = 3, },
ManualFontKerningPlacement = Input {
Value = StyledText {
Array = {
},
Value = ""
},
},
},
ViewInfo = OperatorInfo { Pos = { 725.333, 192.818 } },
},
Text1 = TextPlus {
CtrlWZoom = false,
Inputs = {
GlobalIn = Input { Value = 1, },
Width = Input { Value = 1920, },
Height = Input { Value = 1080, },
["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
StyledText = Input {
Value = "23",
Expression = "Text(time)",
},
Font = Input { Value = "Open Sans", },
Style = Input { Value = "Bold", },
VerticalJustificationNew = Input { Value = 3, },
HorizontalJustificationNew = Input { Value = 3, },
ManualFontKerningPlacement = Input {
Value = StyledText {
Array = {
},
Value = ""
},
},
},
ViewInfo = OperatorInfo { Pos = { 570, 193.424 } },
},
Text3 = TextPlus {
Inputs = {
GlobalIn = Input { Value = 1, },
Width = Input { Value = 1920, },
Height = Input { Value = 1080, },
["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
StyledText = Input {
Value = "36",
Expression = "Text(iif(Text1.StyledText.Value-Text2.StyledText.Value < 0, 0, Text1.StyledText.Value-Text2.StyledText.Value))",
},
Font = Input { Value = "Open Sans", },
Style = Input { Value = "Bold", },
VerticalJustificationNew = Input { Value = 3, },
HorizontalJustificationNew = Input { Value = 3, },
ManualFontKerningPlacement = Input {
Value = StyledText {
Array = {
},
Value = ""
},
},
},
ViewInfo = OperatorInfo { Pos = { 938.667, 184.939 } },
},
Merge2 = Merge {
Inputs = {
Background = Input {
SourceOp = "Merge1",
Source = "Output",
},
Foreground = Input {
SourceOp = "Text3",
Source = "Output",
},
Center = Input { Value = { 0.634375, 0.5 }, },
PerformDepthMerge = Input { Value = 0, },
},
ViewInfo = OperatorInfo { Pos = { 938.667, 355.515 } },
},
Merge1 = Merge {
Inputs = {
Background = Input {
SourceOp = "Text2",
Source = "Output",
},
Foreground = Input {
SourceOp = "Text1",
Source = "Output",
},
Center = Input { Value = { 0.3546875, 0.5 }, },
PerformDepthMerge = Input { Value = 0, },
},
ViewInfo = OperatorInfo { Pos = { 725.333, 355.515 } },
}
}
}


Or if you want to have better access to Lua then use the ":". This has the benefit of being a little easier to debug.
Same setup, only added another Text+:
: x = Text1.StyledText.Value-Text2.StyledText.Value if x < 0 then return 0 else return x end

Code: Select all
{
Tools = ordered() {
Text1 = TextPlus {
Inputs = {
GlobalIn = Input { Value = 1, },
Width = Input { Value = 1920, },
Height = Input { Value = 1080, },
["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
StyledText = Input {
Value = "23",
Expression = "Text(time)",
},
Font = Input { Value = "Open Sans", },
Style = Input { Value = "Bold", },
VerticalJustificationNew = Input { Value = 3, },
HorizontalJustificationNew = Input { Value = 3, },
ManualFontKerningPlacement = Input {
Value = StyledText {
Array = {
},
Value = ""
},
},
},
ViewInfo = OperatorInfo { Pos = { 570, 193.424 } },
},
Text2 = TextPlus {
NameSet = true,
Inputs = {
GlobalIn = Input { Value = 1, },
Width = Input { Value = 1920, },
Height = Input { Value = 1080, },
["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
StyledText = Input {
Value = "-13",
Expression = "Text(-time+10)",
},
Font = Input { Value = "Open Sans", },
Style = Input { Value = "Bold", },
VerticalJustificationNew = Input { Value = 3, },
HorizontalJustificationNew = Input { Value = 3, },
ManualFontKerningPlacement = Input {
Value = StyledText {
Array = {
},
Value = ""
},
},
},
ViewInfo = OperatorInfo { Pos = { 725.333, 192.818 } },
},
Text3 = TextPlus {
Inputs = {
GlobalIn = Input { Value = 1, },
Width = Input { Value = 1920, },
Height = Input { Value = 1080, },
["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
StyledText = Input {
Value = "36",
Expression = "Text(iif(Text1.StyledText.Value-Text2.StyledText.Value < 0, 0, Text1.StyledText.Value-Text2.StyledText.Value))",
},
Font = Input { Value = "Open Sans", },
Style = Input { Value = "Bold", },
VerticalJustificationNew = Input { Value = 3, },
HorizontalJustificationNew = Input { Value = 3, },
ManualFontKerningPlacement = Input {
Value = StyledText {
Array = {
},
Value = ""
},
},
},
ViewInfo = OperatorInfo { Pos = { 938.667, 184.939 } },
},
Text3_1 = TextPlus {
CtrlWZoom = false,
Inputs = {
GlobalIn = Input { Value = 1, },
Width = Input { Value = 1920, },
Height = Input { Value = 1080, },
["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
StyledText = Input {
Value = "32",
Expression = ": x = Text1.StyledText.Value-Text2.StyledText.Value if x < 0 then return 0 else return x end",
},
Font = Input { Value = "Open Sans", },
Style = Input { Value = "Bold", },
VerticalJustificationNew = Input { Value = 3, },
HorizontalJustificationNew = Input { Value = 3, },
ManualFontKerningPlacement = Input {
Value = StyledText {
Array = {
},
Value = ""
},
},
},
ViewInfo = OperatorInfo { Pos = { 1117.33, 174.03 } },
},
Merge3 = Merge {
Inputs = {
Background = Input {
SourceOp = "Merge2",
Source = "Output",
},
Foreground = Input {
SourceOp = "Text3_1",
Source = "Output",
},
Center = Input { Value = { 0.738541666666667, 0.5 }, },
PerformDepthMerge = Input { Value = 0, },
},
ViewInfo = OperatorInfo { Pos = { 1117.33, 355.515 } },
},
Merge2 = Merge {
Inputs = {
Background = Input {
SourceOp = "Merge1",
Source = "Output",
},
Foreground = Input {
SourceOp = "Text3",
Source = "Output",
},
Center = Input { Value = { 0.634375, 0.5 }, },
PerformDepthMerge = Input { Value = 0, },
},
ViewInfo = OperatorInfo { Pos = { 938.667, 355.515 } },
},
Merge1 = Merge {
Inputs = {
Background = Input {
SourceOp = "Text2",
Source = "Output",
},
Foreground = Input {
SourceOp = "Text1",
Source = "Output",
},
Center = Input { Value = { 0.3546875, 0.5 }, },
PerformDepthMerge = Input { Value = 0, },
},
ViewInfo = OperatorInfo { Pos = { 725.333, 355.515 } },
}
}
}
UserNoah wrote: The text() turns everything into a string so the Text+ tool can display it as such. But you can't subtract two strings like numbers. So just get rid of the Text() functions inside the iif.
Try something like this:

Text(iif(Text1.StyledText.Value-Text2.StyledText.Value < 0, 0, Text1.StyledText.Value-Text2.StyledText.Value))



Thank You so much , that worked perfectly. You are awesome .
-
➤ DVR 18.02 Studio
CPU: Ryzen 9 3900XT
MB: Gigabyte B550 Vision D-P
➤ WiFi 6 , BT 5 , 2.5 Gb Ethernet
RAM: 64 GB
GPU: Sapphire Nitro+ 6700 XT 12 GB
PSU: 850W 80+ Gold
OS: Win 10 Pro 21H1 Build 19043.1202
Follow us
 
推荐文章