Author Topic: Just a silly flow question I think...?  (Read 8392 times)

0 Members and 1 Guest are viewing this topic.

Scrripty

  • Guest
Just a silly flow question I think...?
« on: September 11, 2009, 08:39:40 AM »
0
I have a question with code example.  How much of a difference does a few extra lines of code really make?  Like in this example:
Code: [Select]
       menu get specials  ;primary
        IF #menures = 2 && #mana >= !PrimaryMana
        {
          gosub execPrimary
          RETURN
        }
        menu get specials  ;secondary
        IF #menures = 3
        {
          IF #mana >= !SecondaryMana
          {
             gosub execSecondary
          }
          RETURN
        }
      RETURN

The top part of the sub is done with the if built into the first if... basically just combined, and the bottom one is the "old" way I did it.  Would it really make all that much difference in a few thousand lines of code if I went through and changed them to the "new" way?  I have a LOT of subs that look like this tho, and I could probly condense a LOT like this...  Worth it or no?  And why if you would...  It cuts that first part of the sub down to 6 lines from 10.  If the script is processing 10 lines of code per cycle... that's a pretty big net in speed isn't it?  Like 40 percent over the course of a large script, and if you don't have any #lpc optimizing done like me... :)
« Last Edit: September 11, 2009, 08:46:02 AM by Scripty »

Offline Masscre

  • Gran Master Jester !!
  • Scripthack
  • *
  • Posts: 4615
  • Activity:
    0%
  • Reputation Power: 55
  • Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!
  • Gender: Male
  • Air Guitar Commander !!
  • Respect: +144
  • Referrals: 1
    • View Profile
Re: Just a silly flow question I think...?
« Reply #1 on: September 11, 2009, 08:44:15 AM »
0
It solely depends on the amount of time and processes that the live compiler has to do to get it done.  It could make the process easier and in case make the run less cpu dependant, which inpoint would make the script run faster or could load something up or make it take more steps to finish the process incase offsetting the timing and also making the whole process as a whole alot slower.

Scrripty

  • Guest
Re: Just a silly flow question I think...?
« Reply #2 on: September 11, 2009, 08:53:44 AM »
0
It solely depends on the amount of time and processes that the live compiler has to do to get it done.  It could make the process easier and in case make the run less cpu dependant, which inpoint would make the script run faster or could load something up or make it take more steps to finish the process incase offsetting the timing and also making the whole process as a whole alot slower.

Well I'm to the point now where I can FEEL I need some speed.  If that makes sense.  I know I can optimize a TON of script and take out a LOT of lines.  I bet I could cut out about 20 percent of my script by just optimizing with what I've learned.  I'm just wondering how much I'll ACTUALLY gain.  I have #lpc set to 10 in the script.  That's VERY low.  I could set it to 14 and get the same benefit right? :)

Offline Masscre

  • Gran Master Jester !!
  • Scripthack
  • *
  • Posts: 4615
  • Activity:
    0%
  • Reputation Power: 55
  • Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!
  • Gender: Male
  • Air Guitar Commander !!
  • Respect: +144
  • Referrals: 1
    • View Profile
Re: Just a silly flow question I think...?
« Reply #3 on: September 11, 2009, 09:01:05 AM »
0
Yes and no depends on the processing being done that you are speeding up. Also how it will handle on a dial-up, DSL, Cable connection. Also if it is just processing lines or if its is waiting for actions. This will make a big difference.  But the best way to know is to try it out.  ;D

Scrripty

  • Guest
Re: Just a silly flow question I think...?
« Reply #4 on: September 11, 2009, 09:08:18 AM »
0
I'm just trying to prioritize what I ACTUALLY want to do in my head. :)  I think I'll just optimize.  With my new menu, I can almost visually see each thing processing now when I set how often the menu updates to really low.  It's given me some really good insight into how things are getting processed.  Plus it's gotten so big, and there's so much being done, I really have to prioritize WHAT gets done first, and do it based on how important it is that each specific thing is done at what time.  It's annoying. :)  So I'm considering ways to eek out every bit of script and time I can.  Optimizing casting is one way.  By FORCING the sub to wait for faster cast recovery to be up and not returning out and coming back... I'm saving some time and cycles there.  Not making the script endlessly loop through stuff it's just going to sub out of anyways to come back and cast the same thing...  when all it would take is a .50 second wait for the fcr to be up and cast the spell...  I guess that's more flow optimizing.  But if I take out 20 percent of the script, that's 20 percent more it's going to check subs that might need to cast in theory right? :)  Sorry just thinking out loud.

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: Just a silly flow question I think...?
« Reply #5 on: September 11, 2009, 09:24:32 AM »
0
If you really want to see where your speed is going just put a timer in. Use a simple display to show the current #sCnt, then have it displayed at various points in your script.

I like it in a menu, but you could put it over your head....

Code: [Select]
loop
if something A
  gosub A
if something B
  gosub B
until #false

sub A
event ExMsg #charID 3 0 Sub A begin #sCnt
the rest of Sub A
event ExMsg #charID 3 0 Sub A end #sCnt
return

Granted that adds some cycles to the entire process, but it allows you to see exactly how much time is being spent in each part of the script.
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.

Scrripty

  • Guest
Re: Just a silly flow question I think...?
« Reply #6 on: September 11, 2009, 10:00:16 AM »
0
I'll have to send the newest version to you in your junk mail Cerv.  I've got checks upon checks now.  It tells you where it's at, what it's doing, low mana checks for everything... I've been using that to diagnose problems.  Also my new menu allows you to "see" it visually if you let it update in near real time.  It's fun to watch.  When I get all the info I want on the new menu, diagnosing suit problems will be so easy. :)

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: Just a silly flow question I think...?
« Reply #7 on: September 11, 2009, 10:27:04 AM »
0
Cool, I'll look forward to using it one day, if EUO ever updates LOL.

I like having a "diag" mode in scripts. Turn it on/off at the beginning and allow you to see timings, or other things going on.
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.

Scrripty

  • Guest
Re: Just a silly flow question I think...?
« Reply #8 on: September 11, 2009, 10:35:49 AM »
0
Cool, I'll look forward to using it one day, if EUO ever updates LOL.

I like having a "diag" mode in scripts. Turn it on/off at the beginning and allow you to see timings, or other things going on.

That's a good idea, I'm not so far along with it, that I can't add a menu option and make it a diagnostic mode. :)  if #menures = #true's all over the place with little bits of info on what's going on at that exact moment?  I like it.  I'll add that to the "SHOULD HAVE BEEN DONE YESTERDAY" list. :)

Offline Masscre

  • Gran Master Jester !!
  • Scripthack
  • *
  • Posts: 4615
  • Activity:
    0%
  • Reputation Power: 55
  • Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!Masscre is leading the good life!
  • Gender: Male
  • Air Guitar Commander !!
  • Respect: +144
  • Referrals: 1
    • View Profile
Re: Just a silly flow question I think...?
« Reply #9 on: September 11, 2009, 11:43:35 AM »
0
This all sounds good Twinkle McNugget and i like you thought process.  I want to look over some of your diag process to get some ideas for mine :)

Scrripty

  • Guest
Re: Just a silly flow question I think...?
« Reply #10 on: September 11, 2009, 12:18:41 PM »
0
This all sounds good Twinkle McNugget and i like you thought process.  I want to look over some of your diag process to get some ideas for mine :)

If you haven't seen the new menu there's a picture of it here. http://www.scriptuo.com/index.php?topic=2166.msg19670#msg19670

There's also an old version in that thread somewhere attached to a post.  It's got all the old casting errors tho that I've since fixed.  Well I'm actually still working on them, but they've pretty much got a fork stuck in them cause they're DONE. :)



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: Just a silly flow question I think...?
« Reply #11 on: September 11, 2009, 05:38:29 PM »
0
setinng LPC 100   would effectively be a 10x increase in speed.  Dont be affraid to set the LPC higher in certain sections of your code .. just as fast journal scanning.. set LPC 1000 and then set back down after journal scan is done.

In my buffbar scanner (pixel scanning) the LPC is defaulty set to 9999  (bascially max)

As far as you code... Less lines is easier to read thus debug and the newer method needs less {} so thats better... But might I also suggest that you start thinknig about only useing one Return Per sub.. makes code much more resilient in the long run.  Eg like below

Code: [Select]
menu get specials  ;primary Or Secondary
set !MenuRes #MenuRes
IF !menures = 2 && #mana >= !PrimaryMana
   gosub execPrimary
IF !menures = 3 && #mana >= !SecondaryMana
   gosub execSecondary
RETURN

Note: Less that 1/2 the lines used as your original code and i find much easier to read.
« Last Edit: September 11, 2009, 05:40:54 PM by Endless Night »
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: Just a silly flow question I think...?
« Reply #12 on: September 11, 2009, 05:41:07 PM »
0
Yea I know about #lpc, but why does one return make code more resilient?  Oh I think I get it... it's just less lines... and less jumping around... more compact and such? :)  I have SO much jumping around tho... I should throw my ls sub up so you can see THAT monster. haha  I did it. :)  I can cut a TON out of that... 

Code: [Select]
 ;==========================Lightning Strike==================================
  sub ls
    menu get 13 ;Lightning Strike;Primary:Secondary
    IF #menures = #true
    {
      menu get 14          ; WS Mana Check
      IF #menures = #true
      {
        menu get specials  ;ls
        IF #menures = 1 && #mana > !LSManaPercentage
        {
          gosub lsSpecial
          RETURN
        }
        menu get specials  ;primary
        IF #menures = 2 && #mana >= !PrimaryMana
        {
          gosub execPrimary
          RETURN
        }
        menu get specials  ;secondary
        IF #menures = 3
        {
          IF #mana >= !SecondaryMana
          {
             gosub execSecondary
          }
          RETURN
        }
      RETURN
      }
      menu get 25          ;Curse Wep
      IF #menures = #true && !CRWTimer < #sysTime
         gosub CurseWeapon
      menu get specials    ;ls
      IF #menures = 1
      {
         gosub lsSpecial
         RETURN
      }
      menu get specials    ;primary
      IF #menures = 2
      {
        IF #mana >= !PrimaryMana
        {
           gosub execPrimary
        }
        RETURN  
      }
      menu get specials     ;secondary
      IF #menures = 3
      {
        IF #mana >= !SecondaryMana
        {
           gosub execSecondary  
        }
        RETURN
      }  
    }
  RETURN
  ;============================================================================
« Last Edit: September 11, 2009, 05:59:29 PM by Scripty »

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13303
  • Activity:
    0.4%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Just a silly flow question I think...?
« Reply #13 on: September 12, 2009, 12:03:20 PM »
0
I have to agree with EN with the lots-o-returns.  This section:

Code: [Select]
        menu get specials  ;ls
        IF #menures = 1 && #mana > !LSManaPercentage
        {
          gosub lsSpecial
          RETURN
        }
        menu get specials  ;primary
        IF #menures = 2 && #mana >= !PrimaryMana
        {
          gosub execPrimary
          RETURN
        }
        menu get specials  ;secondary
        IF #menures = 3
        {
          IF #mana >= !SecondaryMana
          {
             gosub execSecondary
          }
          RETURN
        }
      RETURN

Can be trimmed to:

Code: [Select]
        menu get specials  ;ls
        IF #menures = 1 && #mana > !LSManaPercentage
          gosub lsSpecial

        menu get specials  ;primary
        IF #menures = 2 && #mana >= !PrimaryMana
          gosub execPrimary

        menu get specials  ;secondary
        IF #menures = 3 && #mana >= !SecondaryMana
             gosub execSecondary
      RETURN

That seems just more readable to me and doesn't change execution flow too much.
Please read the ScriptUO site RULES
Come play RIFT with me!

Scrripty

  • Guest
Re: Just a silly flow question I think...?
« Reply #14 on: September 12, 2009, 12:21:15 PM »
0
I have to agree with EN with the lots-o-returns.  This section:
That seems just more readable to me and doesn't change execution flow too much.

While you were posting that I did this:
Basically cut that sub in half.  Sped it up by double then... Should net me a tiny bit of speed when toggling specials...  Thanks guys, I'm gonna keep looking.  Remember this is my FIRST full fledged script I've EVER done.  I've done TONS of little things, a few hundred lines... but this is huge to me. :)  I'm at 3000 lines and counting now.  Lots of documentation tho.  That's what I was saying I could probly cut the script by AT LEAST 20 percent, and if that sub is any indication I could probly go 40 to 50. :)

Code: [Select]
 ;==========================Lightning Strike==================================
  sub ls
    menu get 13 ;Lightning Strike;Primary:Secondary
    IF #menures = #true
    {
      menu get 14          ; WS Mana Check
      IF #menures = #true
      {
        menu get specials  ;ls
        IF #menures = 1 && #mana > !LSManaPercentage
          gosub lsSpecial
        menu get specials  ;primary
        IF #menures = 2 && #mana >= !PrimaryMana
          gosub execPrimary
        menu get specials  ;secondary
        IF #menures = 3 && #mana >= !SecondaryMana
           gosub execSecondary
        RETURN
      }
      menu get specials    ;ls
      IF #menures = 1
         gosub lsSpecial
      menu get specials    ;primary
      IF #menures = 2 && #mana >= !PrimaryMana
         gosub execPrimary
      menu get specials     ;secondary
      IF #menures = 3 && #mana >= !SecondaryMana
         gosub execSecondary
    }
  RETURN
  ;============================================================================
« Last Edit: September 12, 2009, 12:26:09 PM by Scripty »

Tags: