Author Topic: Sending Data Strings after a GoSub X XX XXX XXXX XXXXX...  (Read 6492 times)

0 Members and 1 Guest are viewing this topic.

Offline PauloniusTopic starter

  • Elite
  • *
  • *
  • Posts: 2040
  • Activity:
    0%
  • Reputation Power: 29
  • Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.
  • Respect: +162
  • Referrals: 1
    • View Profile
Sending Data Strings after a GoSub X XX XXX XXXX XXXXX...
« on: November 18, 2009, 08:25:13 AM »
0
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:

Code: [Select]
; 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

Code: [Select]
; 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

Code: [Select]
; 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
This coin declares Caesar is "Dictator for Life." He did serve as Dictator for the remainder of his life, but his life would end only a few weeks after this issue. For Caesar to put his image on coins and essentially declare himself king was too much for Brutus and his republican allies.

"If everything seems under control, you're not going fast enough'
-Mario Andretti

"If everyone is thinking alike, someone isn't thinking."
- General George Patton Jr

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: Sending Data Strings after a GoSub X XX XXX XXXX XXXXX...
« Reply #1 on: November 18, 2009, 08:44:41 AM »
0
Yep, always assign a local variable to the %1, %2 etc values and/or be sure to use Namespaces in your subs as applicable!
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline PauloniusTopic starter

  • Elite
  • *
  • *
  • Posts: 2040
  • Activity:
    0%
  • Reputation Power: 29
  • Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.
  • Respect: +162
  • Referrals: 1
    • View Profile
Re: Sending Data Strings after a GoSub X XX XXX XXXX XXXXX...
« Reply #2 on: November 18, 2009, 08:47:40 AM »
0
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...
This coin declares Caesar is "Dictator for Life." He did serve as Dictator for the remainder of his life, but his life would end only a few weeks after this issue. For Caesar to put his image on coins and essentially declare himself king was too much for Brutus and his republican allies.

"If everything seems under control, you're not going fast enough'
-Mario Andretti

"If everyone is thinking alike, someone isn't thinking."
- General George Patton Jr

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: Sending Data Strings after a GoSub X XX XXX XXXX XXXXX...
« Reply #3 on: November 18, 2009, 09:01:32 AM »
0
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
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline Cerveza

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: Sending Data Strings after a GoSub X XX XXX XXXX XXXXX...
« Reply #4 on: November 18, 2009, 09:04:33 AM »
0
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...

Code: [Select]
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.
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: Sending Data Strings after a GoSub X XX XXX XXXX XXXXX...
« Reply #5 on: November 18, 2009, 09:18:30 AM »
0
I Admit i didnt read all of above so this might be useless advice...

but why not do smoething like this

Code: [Select]
For !x 1  !ExpectedParmeterspassed
  {
  set !Parameter . !x  NONE
  If %0 >= !x
     Set !Parameter . !x  % . !x
  }

OR

Code: [Select]
If %0 < !ExpectedParmeterspassed
 {
  set !start %0 + 1
  For !x !Start !ExpectedParmeterspassed
    {
    set % . !x  N/A
    }
  }
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Scrripty

  • Guest
Re: Sending Data Strings after a GoSub X XX XXX XXXX XXXXX...
« Reply #6 on: November 18, 2009, 09:50:11 AM »
0
I Admit i didnt read all of above so this might be useless advice...

but why not do smoething like this

Code: [Select]
For !x 1  !ExpectedParmeterspassed
  {
  set !Parameter . !x  NONE
  If %0 >= !x
     Set !Parameter . !x  % . !x
  }

OR

Code: [Select]
If %0 < !ExpectedParmeterspassed
 {
  set !start %0 + 1
  For !x !Start !ExpectedParmeterspassed
    {
    set % . !x  N/A
    }
  }


I love EN.

Offline PauloniusTopic starter

  • Elite
  • *
  • *
  • Posts: 2040
  • Activity:
    0%
  • Reputation Power: 29
  • Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.
  • Respect: +162
  • Referrals: 1
    • View Profile
Re: Sending Data Strings after a GoSub X XX XXX XXXX XXXXX...
« Reply #7 on: November 18, 2009, 11:30:27 AM »
0
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...
This coin declares Caesar is "Dictator for Life." He did serve as Dictator for the remainder of his life, but his life would end only a few weeks after this issue. For Caesar to put his image on coins and essentially declare himself king was too much for Brutus and his republican allies.

"If everything seems under control, you're not going fast enough'
-Mario Andretti

"If everyone is thinking alike, someone isn't thinking."
- General George Patton Jr

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: Sending Data Strings after a GoSub X XX XXX XXXX XXXXX...
« Reply #8 on: November 18, 2009, 11:42:00 AM »
0
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.
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline PauloniusTopic starter

  • Elite
  • *
  • *
  • Posts: 2040
  • Activity:
    0%
  • Reputation Power: 29
  • Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.
  • Respect: +162
  • Referrals: 1
    • View Profile
Re: Sending Data Strings after a GoSub X XX XXX XXXX XXXXX...
« Reply #9 on: November 18, 2009, 11:58:06 AM »
0
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.
This coin declares Caesar is "Dictator for Life." He did serve as Dictator for the remainder of his life, but his life would end only a few weeks after this issue. For Caesar to put his image on coins and essentially declare himself king was too much for Brutus and his republican allies.

"If everything seems under control, you're not going fast enough'
-Mario Andretti

"If everyone is thinking alike, someone isn't thinking."
- General George Patton Jr

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: Sending Data Strings after a GoSub X XX XXX XXXX XXXXX...
« Reply #10 on: November 18, 2009, 12:10:11 PM »
0
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  :-* )
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Scrripty

  • Guest
Re: Sending Data Strings after a GoSub X XX XXX XXXX XXXXX...
« Reply #11 on: November 18, 2009, 12:12:10 PM »
0
Yes thiers a name .. PARAMETERS

SS:  His scripting makes me drool with envy, but his SPELLING... a WHOLE nother story. :) haha j/k EN!

Offline Cerveza

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: Sending Data Strings after a GoSub X XX XXX XXXX XXXXX...
« Reply #12 on: November 18, 2009, 12:21:50 PM »
0
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
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: Sending Data Strings after a GoSub X XX XXX XXXX XXXXX...
« Reply #13 on: November 18, 2009, 12:32:23 PM »
0
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.

When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: Sending Data Strings after a GoSub X XX XXX XXXX XXXXX...
« Reply #14 on: November 18, 2009, 01:27:46 PM »
0
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.

Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Tags: