Hey there,
I am playing Litcube´s Universe at the moment. Many scripts do not work with this mod, so I decided to take my first steps into scripting myself.
So far I already wrote some cool scripts, but I am kind of stuck with the current script.
Any help one of you could provide, will be highly appreciated.
The Script:
Basically the script will get a ware array of a specific factory/ dock etc.
Furthermore it will create a menu where you can select one specific ware out of the pool of availabe wares at the selected factory/ dock.
After this the script opens a new menu where you can change the amount of the stored ware to a percentage of 0, 25, 50, 75 or 100.
So far so good.
The script is working fine and it does what it is supposed to do.
BUT:
The first entry of the first menu (where you can chose a stored ware) is not selectable. Every other entry works fine.
I can not figure out, what went wrong with this script. I tried to get the script (completely) working but can not find the source of the issue.
Here you can see three images; first one shows the code, the second one shows the first menu and the third one shows the sub-menu, which will show up, when you select s.th. in the first menu:
https://imgur.com/gallery/LcOfQRo
Hopefully someone got the special hint to make the first item on the list selectable too.
Best regards
This is the code I am using right now:
<![CDATA[
$input = [THIS] -> get user input: type=Var/Station, title='Select A Station'
$TradeableWares = $input -> get tradeable ware array from station
$IdStation = $input -> get ID code
$NameStation = $input -> get name
$SizeArray1 = size of array $TradeableWares
$A = 'a'
$B = 'b'
$C = 'c'
$D = 'd'
$E = 'e'
$counterarray = 0
$returnvalue = 0
$w = $TradeableWares[$counterarray]
$TextIntro = sprintf: fmt='Tradeabel Wares Of Your %s (%s)', $NameStation, $IdStation, null, null, null
$CustMenu = create custom menu array: heading='Your Selected Ware'
$custmenu2 = create custom menu array
add custom menu item to array $custmenu2: text=' 0 %' returnvalue=$A
add custom menu item to array $custmenu2: text=' 25 %' returnvalue=$B
add custom menu item to array $custmenu2: text=' 50 %' returnvalue=$C
add custom menu item to array $custmenu2: text=' 75 %' returnvalue=$D
add custom menu item to array $custmenu2: text='100 %' returnvalue=$E
while $counterarray < $SizeArray1
$w = $TradeableWares[$counterarray]
$aow1 = $input -> get max. store amount of ware $w
$aow2 = $input -> get amount of ware $w in cargo bay
$aow3 = $input -> get ware storage percentage: ware=$w
$text = sprintf: fmt='%s (%s // %s) (%s %)', $w, $aow2, $aow1, $aow3, null
add custom menu item to array $CustMenu: text=$text returnvalue=$returnvalue
@ $wait = wait 10 ms
inc $counterarray =
inc $returnvalue =
end
Menu1:
$return1 = open custom menu: title='Tradeable Wares' description=$TextIntro option array=$CustMenu
if $return1 == $returnvalue
goto label Menu2
else if $return1 == -1
@ $scriptcall = [THIS] -> call script AA.Menu :
return null
end
Menu2:
$return02 = open custom menu: title='Set Your Stock Level' description='Stock Manipulation' option array=$custmenu2
$getreturnvalue = 0
while $getreturnvalue < $returnvalue
$ware = $TradeableWares[$getreturnvalue]
$maxamount = $input -> get max. store amount of ware $ware
$A1 = $maxamount / 4
$A2 = $maxamount / 4 * 2
$A3 = $maxamount / 4 * 3
$A4 = $maxamount
if $return1 == $getreturnvalue AND $return02 == $A
$a = $input -> add -9999999 units of $ware
else if $return1 == $getreturnvalue AND $return02 == $B
$b = $input -> add -9999999 units of $ware
$c = $input -> add $A1 units of $ware
else if $return1 == $getreturnvalue AND $return02 == $C
$d = $input -> add -9999999 units of $ware
$e = $input -> add $A2 units of $ware
else if $return1 == $getreturnvalue AND $return02 == $D
$f = $input -> add -9999999 units of $ware
$g = $input -> add $A3 units of $ware
else if $return1 == $getreturnvalue AND $return02 == $E
$h = $input -> add -9999999 units of $ware
$i = $input -> add $A4 units of $ware
else if $return1 == $getreturnvalue AND $return02 == -1
goto label Menu1
end
@ $wait = wait 10 ms
inc $getreturnvalue =
end
return null[/list]
Unexpected Issue With Script-Editor
Moderators: Moderators for English X Forum, Scripting / Modding Moderators
@Joubarbe
Unfortunately it causes a gap of 1 integer to $getreturnvalue.
For anyone who might be interested in this topic:
To work around this I added a new variable $truegetreturnvalue which starts at 0, while the $getreturnvalue starts at 1.
This closes the gap between $returnvalue and $getreturnvalue.
The script looks like this now:
$input = [THIS]-> get user input: type=[Var/Station], title='Select A Station'
$TradeableWares = $input-> get tradeable ware array from station
$IdStation = $input-> get ID code
$NameStation = $input-> get name
$SizeArray1 = size of array $TradeableWares
$A = 'a'
$B = 'b'
$C = 'c'
$D = 'd'
$E = 'e'
$counterarray = 0
$returnvalue = 1
$w = $TradeableWares[$counterarray]
$TextIntro = sprintf: fmt='Tradeabel Wares Of Your %s (%s)', $NameStation, $IdStation, null, null, null
$CustMenu = create custom menu array: heading='Your Selected Ware'
$custmenu2 = create custom menu array
add custom menu item to array $custmenu2: text=' 0 %' returnvalue=$A
add custom menu item to array $custmenu2: text=' 25 %' returnvalue=$B
add custom menu item to array $custmenu2: text=' 50 %' returnvalue=$C
add custom menu item to array $custmenu2: text=' 75 %' returnvalue=$D
add custom menu item to array $custmenu2: text='100 %' returnvalue=$E
while $counterarray < $SizeArray1
$w = $TradeableWares[$counterarray]
$aow1 = $input-> get max. store amount of ware $w
$aow2 = $input-> get amount of ware $w in cargo bay
$aow3 = $input-> get ware storage percentage: ware=$w
$text = sprintf: fmt='%s (%s // %s) (%s %)', $w, $aow2, $aow1, $aow3, null
add custom menu item to array $CustMenu: text=$text returnvalue=$returnvalue
$wait = wait 10 ms
inc $counterarray
inc $returnvalue
end
Menu1:
$return1 = open custom menu: title='Tradeable Wares' description=$TextIntro option array=$CustMenu
if $return1 == $returnvalue
goto label Menu2:
else if $return1 == -1
$scriptcall = [THIS]-> call script 'AA.Menu' :
return null
end
Menu2:
$return02 = open custom menu: title='Set Your Stock Level' description='Stock Manipulation' option array=$custmenu2
$getreturnvalue = 1
$truegetreturnvalue = 0
while $getreturnvalue < $returnvalue
$ware = $TradeableWares[$truegetreturnvalue]
$maxamount = $input-> get max. store amount of ware $ware
$A1 = $maxamount / 4
$A2 = $maxamount / 4 * 2
$A3 = $maxamount / 4 * 3
$A4 = $maxamount
if $return1 == $getreturnvalue AND $return02 == $A
$a = $input-> add -9999999 units of $ware
else if $return1 == $getreturnvalue AND $return02 == $B
$b = $input-> add -9999999 units of $ware
$c = $input-> add $A1 units of $ware
else if $return1 == $getreturnvalue AND $return02 == $C
$d = $input-> add -9999999 units of $ware
$e = $input-> add $A2 units of $ware
else if $return1 == $getreturnvalue AND $return02 == $D
$f = $input-> add -9999999 units of $ware
$g = $input-> add $A3 units of $ware
else if $return1 == $getreturnvalue AND $return02 == $E
$h = $input-> add -9999999 units of $ware
$i = $input-> add $A4 units of $ware
else if $return1 == $getreturnvalue AND $return02 == -1
goto label Menu1:
end
$wait = wait 10 ms
inc $getreturnvalue
inc $truegetreturnvalue
end
return null
That did the trick. Thank you!!The first element in your list has a $returnvalue of 0. $returnvalue can't be 0.
Unfortunately it causes a gap of 1 integer to $getreturnvalue.
Menu2:
$return02 = open custom menu: title='Set Your Stock Level' description='Stock Manipulation' option array=$custmenu2
$getreturnvalue = 0
while $getreturnvalue < $returnvalue
$ware = $TradeableWares[$getreturnvalue]
$maxamount = $input -> get max. store amount of ware $ware
$A1 = $maxamount / 4
$A2 = $maxamount / 4 * 2
$A3 = $maxamount / 4 * 3
$A4 = $maxamount
if $return1 == $getreturnvalue AND $return02 == $A
$a = $input -> add -9999999 units of $ware
For anyone who might be interested in this topic:
To work around this I added a new variable $truegetreturnvalue which starts at 0, while the $getreturnvalue starts at 1.
This closes the gap between $returnvalue and $getreturnvalue.
The script looks like this now:
$input = [THIS]-> get user input: type=[Var/Station], title='Select A Station'
$TradeableWares = $input-> get tradeable ware array from station
$IdStation = $input-> get ID code
$NameStation = $input-> get name
$SizeArray1 = size of array $TradeableWares
$A = 'a'
$B = 'b'
$C = 'c'
$D = 'd'
$E = 'e'
$counterarray = 0
$returnvalue = 1
$w = $TradeableWares[$counterarray]
$TextIntro = sprintf: fmt='Tradeabel Wares Of Your %s (%s)', $NameStation, $IdStation, null, null, null
$CustMenu = create custom menu array: heading='Your Selected Ware'
$custmenu2 = create custom menu array
add custom menu item to array $custmenu2: text=' 0 %' returnvalue=$A
add custom menu item to array $custmenu2: text=' 25 %' returnvalue=$B
add custom menu item to array $custmenu2: text=' 50 %' returnvalue=$C
add custom menu item to array $custmenu2: text=' 75 %' returnvalue=$D
add custom menu item to array $custmenu2: text='100 %' returnvalue=$E
while $counterarray < $SizeArray1
$w = $TradeableWares[$counterarray]
$aow1 = $input-> get max. store amount of ware $w
$aow2 = $input-> get amount of ware $w in cargo bay
$aow3 = $input-> get ware storage percentage: ware=$w
$text = sprintf: fmt='%s (%s // %s) (%s %)', $w, $aow2, $aow1, $aow3, null
add custom menu item to array $CustMenu: text=$text returnvalue=$returnvalue
$wait = wait 10 ms
inc $counterarray
inc $returnvalue
end
Menu1:
$return1 = open custom menu: title='Tradeable Wares' description=$TextIntro option array=$CustMenu
if $return1 == $returnvalue
goto label Menu2:
else if $return1 == -1
$scriptcall = [THIS]-> call script 'AA.Menu' :
return null
end
Menu2:
$return02 = open custom menu: title='Set Your Stock Level' description='Stock Manipulation' option array=$custmenu2
$getreturnvalue = 1
$truegetreturnvalue = 0
while $getreturnvalue < $returnvalue
$ware = $TradeableWares[$truegetreturnvalue]
$maxamount = $input-> get max. store amount of ware $ware
$A1 = $maxamount / 4
$A2 = $maxamount / 4 * 2
$A3 = $maxamount / 4 * 3
$A4 = $maxamount
if $return1 == $getreturnvalue AND $return02 == $A
$a = $input-> add -9999999 units of $ware
else if $return1 == $getreturnvalue AND $return02 == $B
$b = $input-> add -9999999 units of $ware
$c = $input-> add $A1 units of $ware
else if $return1 == $getreturnvalue AND $return02 == $C
$d = $input-> add -9999999 units of $ware
$e = $input-> add $A2 units of $ware
else if $return1 == $getreturnvalue AND $return02 == $D
$f = $input-> add -9999999 units of $ware
$g = $input-> add $A3 units of $ware
else if $return1 == $getreturnvalue AND $return02 == $E
$h = $input-> add -9999999 units of $ware
$i = $input-> add $A4 units of $ware
else if $return1 == $getreturnvalue AND $return02 == -1
goto label Menu1:
end
$wait = wait 10 ms
inc $getreturnvalue
inc $truegetreturnvalue
end
return null