ScriptUO
Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Paulonius on November 18, 2009, 08:25:13 AM
-
So I have been playing with sending data to various subs to make my scripts more flexible and I came accross a problem with sending different length data strings. It appears that the variables %1 %2 %3, etc, the EUO assigned variables when you use a data string will keep their values until cleared. I think the answer is that you either need to clear them between uses (by assigning N/A, -1, or some other value you can track) or you need to put the clearing value into what would otherwise be the empty slots on your string.
Here is an example that doesn't work because it tries to clear the recurring variables, not the built in number variables:
; GoSub Data String Protocol Testing
Set %CycleCnt 0
REPEAT
Set %CycleCnt %CycleCnt + 1
Gosub Datasub
UNTIL %CycleCnt > 3
Halt
sub Datasub
If %cyclecnt = 1
{
Gosub DisplaySub 1 2 3 4 5 6
Return
}
If %cyclecnt = 2
{
Gosub DisplaySub 1 2 3 4 5 6 7 8
Return
}
If %cyclecnt = 3
{
Gosub DisplaySub 1 2 3 4 5 6
Return
}
Return
Sub DisplaySub
Set %Display1 1000 ; These are an attempt to reset my recurring variables
Set %Display2 1000 ; and this doesn't work
Set %Display3 1000 ; in cycle three the value for %display7 will be 7
Set %Display4 1000 ; because %7 holds that value until it is changed or cleared
Set %Display5 1000
Set %Display6 1000
Set %Display7 1000
Set %Display8 1000
Set %Display1 %1
Set %Display2 %2
Set %Display3 %3
Set %Display4 %4
Set %Display5 %5
Set %Display6 %6
Set %Display7 %7
Set %Display8 %8
Display %Display1 %Display2 %Display3 %Display4 %Display5 %Display6 %Display7 %Display8 hit play to continue
pause
Return
This method works
; GoSub Data String Protocol Testing
Set %CycleCnt 0
REPEAT
Set %CycleCnt %CycleCnt + 1
Gosub Datasub
UNTIL %CycleCnt > 3
Halt
sub Datasub
If %cyclecnt = 1
{
Gosub DisplaySub 1 2 3 4 5 6 1000 1000 ; I can screen for the "empty" data slot
Return ; using a value check
}
If %cyclecnt = 2
{
Gosub DisplaySub 1 2 3 4 5 6 7 8
Return
}
If %cyclecnt = 3
{
Gosub DisplaySub 1 2 3 4 5 6 1000 1000 ; put the dummy variable "1000" in here
Return ; or the script will still assign 7 and 8
}
Return
Sub DisplaySub
Set %Display1 %1
Set %Display2 %2
Set %Display3 %3
Set %Display4 %4
Set %Display5 %5
Set %Display6 %6
Set %Display7 %7
Set %Display8 %8
Display %Display1 %Display2 %Display3 %Display4 %Display5 %Display6 %Display7 %Display8 hit play to continue
pause
Return
And so does this method
; GoSub Data String Protocol Testing
Set %CycleCnt 0
REPEAT
Set %CycleCnt %CycleCnt + 1
Gosub Datasub
UNTIL %CycleCnt > 3
Halt
sub Datasub
Set %1 1000 ; Here I am assigning the dummy variable before I assign my values
Set %2 1000 ; I could also use N/A here
Set %3 1000 ; in cycle three the value for %display7 will be 7
Set %4 1000 ; because %7 holds that value until it is changed or cleared
Set %5 1000
Set %6 1000
Set %7 1000
Set %8 1000
If %cyclecnt = 1
{
Gosub DisplaySub 1 2 3 4 5 6 ; I don't need to do anything with the "empty" data slot
Return ; using a value check will find the clearing value
}
If %cyclecnt = 2
{
Gosub DisplaySub 1 2 3 4 5 6 7 8
Return
}
If %cyclecnt = 3
{
Gosub DisplaySub 1 2 3 4 5 6
Return
}
Return
Sub DisplaySub
Set %Display1 %1
Set %Display2 %2
Set %Display3 %3
Set %Display4 %4
Set %Display5 %5
Set %Display6 %6
Set %Display7 %7
Set %Display8 %8
Display %Display1 %Display2 %Display3 %Display4 %Display5 %Display6 %Display7 %Display8 hit play to continue
pause
Return
-
Yep, always assign a local variable to the %1, %2 etc values and/or be sure to use Namespaces in your subs as applicable!
-
Care to elaborate on namespace use in this context 12? I would love to learn a bit more about the subject while its fresh for me...
-
Well, TBH, I have to re-read your post with a more detailed eye to make sure I understand everything you are pointing out correctly. With that said, I think the concept behind namespaces is to allow you to localize variables without impacting other variables that are being used globally and may share the same name. One of the issues I see in EUO code is that there really isn't much of a difference betweek locals (%) and globals (!) in that "locals" are treated like globals by EUO. In some languages a "local" is available ONLY in the sub it is declared in whereby a "global" is available code-wide (essentially), I have found this isn't the case in EUO script thus the use of namespaces within subs so you can maintain the integrity of your sending sub data.
Again, I may be misreading things (I'm at work and am going fast) and I'm also not the foremost expert on any of these topics, TM has been my Namespace teacher and I may be wrong all over the place! ;)
X
-
Namespace just reserves an area in your script to use ! variables, that will be cleared when you leave that space.
Think of it as a bench in your workshop. When this portion of your job requires using the wrench, hammer and chainsaw you put them all on the workbench together. Once you finish with that portion of your job you put them back in the tool chest.
Local means one tab of EUO, GLOBAL means the variable can be used in other tabs (see the GBot).
Here ya go...
sub MoveRandomCoord
namespace push ; this tells euo that the old variables should be saved, that this is a unique area
namespace local RS ; this says LOCAL (one instance/tab of euo) and names this area
set !LocationX %1 ; as stated, you should always rename the attributes you sent into the gosub
set !LocationY %2
set !Radius %3
set !RandomX #random % (( !LocationX - !Radius ) + ( !Radius * 2 )) - ( !LocationX - !Radius ) + 1 + ( !LocationX - !Radius )
set !RandomY #random % (( !LocationY - !Radius ) + ( !Radius * 2 )) - ( !LocationX - !Radius ) + 1 + ( !LocationY - !Radius )
move !randomX !randomY 3 10s
namespace pop ; this tells euo your done using this particular "workbench" and to resume normal variable stuff.
return
All the work in the sub uses ! variables. It's a "clean" way to script so you don't get confusion using variables.
-
I Admit i didnt read all of above so this might be useless advice...
but why not do smoething like this
For !x 1 !ExpectedParmeterspassed
{
set !Parameter . !x NONE
If %0 >= !x
Set !Parameter . !x % . !x
}
OR
If %0 < !ExpectedParmeterspassed
{
set !start %0 + 1
For !x !Start !ExpectedParmeterspassed
{
set % . !x N/A
}
}
-
I Admit i didnt read all of above so this might be useless advice...
but why not do smoething like this
For !x 1 !ExpectedParmeterspassed
{
set !Parameter . !x NONE
If %0 >= !x
Set !Parameter . !x % . !x
}
OR
If %0 < !ExpectedParmeterspassed
{
set !start %0 + 1
For !x !Start !ExpectedParmeterspassed
{
set % . !x N/A
}
}
I love EN.
-
Good stuff, 12X, Cerv. I had been pretty vague on namespace and the ! variables, so that is helpful.
EN, you are shooting over my head with that scary math and no alphabety things to explain WTF it does.
In my scenario, reapeatedly going from a data sub over to second sub carrying values in the EUO numbered variables would it be possible to use namespace to keep from assigning a persistent value to the %1, %2, %3... string variables [do we have a name for them?] or do I still need a mechanism like ENs for clearing those out -- although I can't use EN's because I dont understand it. I suspect it does the same as a string of Set %1 X lines...
-
the %1, %2, %3... string variables [do we have a name for them?]
Yes thiers a name .. PARAMETERS
and yes my code is the same thing as saying I want 10 parameters (!expectedparameterspassed).. only %0 (eg =5) where passed thier for set %Parmeter1 = %1 %Parementer2 = %2 ..... %Parameter5 = %5 %Parameter6 ... 10 = N/A
In second example it just sets ... %6...%10 to N/A .. without reassigning a localnamed Variable.
Off course with better spelling.
-
Thanks EN. I figured it out by looking at your shout post and re-reading the part about 0% carrying the number of values sent.
-
EN is the "For" master. Cerv, TM, EN, and C2 taught me everything I know (granted, that isn't very much, but what I lack in quantity I like to think I make up in quality :-* )
-
Yes thiers a name .. PARAMETERS
SS: His scripting makes me drool with envy, but his SPELLING... a WHOLE nother story. :) haha j/k EN!
-
EN is the "For" master. Cerv, TM, EN, and C2 taught me everything I know (granted, that isn't very much, but what I lack in quantity I like to think I make up in quality :-* )
Hey now, don't mix me in with those real scripters! I'm a hack and always will be :P
-
EN is the "For" master. Cerv, TM, EN, and C2 taught me everything I know (granted, that isn't very much, but what I lack in quantity I like to think I make up in quality :-* )
Hey now, don't mix me in with those real scripters! I'm a hack and always will be :P
LOL well props to all of the "hacked" tutorials then at UOC and here.
-
but his SPELLING... a WHOLE nother story. :) haha j/k EN!
Hah thats funny... and even thow your kidding its still so true... my spelling is atrocious (spelling) ... If i could spell half the words i use my posts would be much more colourful.
.. thanks for the props guys... i'm glad i taught someone something.. in person im an awful teacher .. just no patience.
-
in person im an awful teacher .. just no patience.
That's me to a T. I can't ever be a tech support guy either. I'd want to reach through the phone and strangle someone.
-
TM and I are the two most patient people I know.
I mean, how can you not be patient with all these people and the HW Quester?