ScriptUO
Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Paulonius on April 13, 2011, 10:59:55 AM
-
I was looking at building a sub that accepts a variable data set and wondering what the most efficient way to reassign the parameters might be.
Specifically, I wanted to run through the parameters in an ascending loop assigning the parameters to a series of variables using concatation.
The result should be that it will assign parameter values to your variable X in ascending order as %X1, %X2, etc, until it has given each parameter a variable assignment.
This is the structure of what I came up with:
Gosub Parameter_Parser 1 12 123 1234 12345 123456
Halt
Sub Parameter_Parser
Set %TotalParameters %0
Set %ParameterCount 0
Repeat
{
Set %ParameterCount %ParameterCount + 1
Set %CurrentParameter % . %ParameterCount
Set %X . %ParameterCount %CurrentParameter
Display Parameter %ParameterCount of %TotalParameters total is %X . %ParameterCount
}
Until %ParameterCount = %TotalParameters
return
-
same thing condensed
Gosub Parameter_Parser 1 12 123 1234 12345 123456
Halt
Sub Parameter_Parser
Set %TotalParameters %0
for %ParameterCount 1 %TotalParameters
Set %X . %ParameterCount % . %ParameterCount
return
I use simular code for a sub to make one sentance with space
gosub makeline this is a test. this is only a test.
display ok #result
halt
sub makeline
if %0 > 0
{
set #result
for %x 1 %0
set #result #result , #spc , % . %x
}
return #result