Author Topic: start/pause buttons for menus  (Read 3443 times)

0 Members and 1 Guest are viewing this topic.

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 3021
  • Activity:
    3.6%
  • Reputation Power: 41
  • Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +206
  • Referrals: 2
    • View Profile
start/pause buttons for menus
« on: March 02, 2013, 10:01:51 AM »
0
I have the start working, Press the start button and it starts fishing and changes the start button to a pause button. When pressing the pause button,  I thought it would pause and change the pause button to a start button and wait for start to be pressed again. Where did I go wrong?

Code: [Select]
;Setup
set %fishingpole XHF_KDF
set %bones BJK_EJK_DJK_YIK_XIK_AJK_ZJK_KJK_FJK_ZIK
set %scissors KAG_JAG
gosub Menu
;===================================================================
sub Menu
menu Clear
menu Window Title Crisis SOS Fisher 2.0
menu Window Color Black
menu Window Size 186 57
menu Font Transparent #true
menu Font Align Right
menu Font Name MS Sans Serif
menu Font Size 10
menu Font Style
menu Font Color WindowText
menu Font BGColor Lime
menu Button Start_Button 44 12 95 33 Start Fishing
menu Show 421 270

if #menubutton <> N/A
     gosub menubuttons
or
if #menubutton = pause
     gosub pause
return
;===================================================================
sub menubuttons
menu HideEUO
  set #menubutton N/A
  repeat
  until #menubutton <> N/A
  menu delete start
    menu Font Color WindowText
     menu Font Size 10
    menu Font BGColor Red
    menu Button pause 44 12 95 33 Pause ; creates new button
 set #menubutton  N/A
 menu delete start
 gosub Fishing
repeat
until #menubutton = start
if #menubutton = start
 
;===================================================================
sub pause
set #menubutton N/A
  repeat
  until #menubutton <> N/A
  menu delete pause
    menu Font Color WindowText
     menu Font Size 10
    menu Font BGColor Green
    menu Button Start 44 12 95 33 Start ; creates new button
 set #menubutton  N/A
 menu delete pause
 gosub menubuttons
repeat
until #menubutton = pause
if #menubutton = pause

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: start/pause buttons for menus
« Reply #1 on: March 02, 2013, 10:28:34 AM »
0
thiers no such command as OR

if #menubutton <> N/A
     gosub menubuttons
or
if #menubutton = pause
     gosub pause

no such command as or in euo script .. you probably want to use ELSE  and wrap the blocks in {},    OR is used on logic conditions like if this or that   but instead of the word or you use ||   ie if this || that

Ok besides that fact the above code will never find the condition  if #menubutton = Pause  as TRUE  ever,   Why ???.. look at logic  if menubutton <> N/A  when menu button = pause its not equal to N/A so executes sub menubuttons .. first thing that sub does is set #menubutton to N/A  so when it returns and compares menubutton to pause .. menubutton now = N/A .


The other thing you or not closing your subs... All subs must end in return.. right now you code is only functioning because it ends and EUO restarts it over and over and over again.
« Last Edit: March 02, 2013, 11:04:53 AM 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."

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 3021
  • Activity:
    3.6%
  • Reputation Power: 41
  • Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +206
  • Referrals: 2
    • View Profile
Re: start/pause buttons for menus
« Reply #2 on: March 02, 2013, 11:36:06 AM »
0
thiers no such command as OR

if #menubutton <> N/A
     gosub menubuttons
or
if #menubutton = pause
     gosub pause

no such command as or in euo script .. you probably want to use ELSE  and wrap the blocks in {},    OR is used on logic conditions like if this or that   but instead of the word or you use ||   ie if this || that

Ok besides that fact the above code will never find the condition  if #menubutton = Pause  as TRUE  ever,   Why ???.. look at logic  if menubutton <> N/A  when menu button = pause its not equal to N/A so executes sub menubuttons .. first thing that sub does is set #menubutton to N/A  so when it returns and compares menubutton to pause .. menubutton now = N/A .


The other thing you or not closing your subs... All subs must end in return.. right now you code is only functioning because it ends and EUO restarts it over and over and over again.

I am very confused right now. I was using this http://www.scriptuo.com/index.php?topic=1535.0 as a guide to help me. I am learning, I think, but I am confused. If you could explain it in a little bit more detail and maybe show a proper example I would greatly appreciate it.  I wish there was more on setting up menu's but found that one post and one on the easyuo forums.

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: start/pause buttons for menus
« Reply #3 on: March 02, 2013, 05:00:39 PM »
0
anaylse below...

Code: [Select]
;Setup
set %fishingpole XHF_KDF
set %bones BJK_EJK_DJK_YIK_XIK_AJK_ZJK_KJK_FJK_ZIK
set %scissors KAG_JAG
gosub DrawMenu
set %ENDScript NO
set %StartFishing NO

repeat
  ; Do some actions
  gosub CheckMenu
  ; do some actions
;  if %StartFishing = YES
;     gosub SingleFishingAction
until %ENDSCRIPT = YES
halt  ; end of script

sub CheckMenu
  if #menubutton = Pause
       gosub PausePressed
  if #menubutton = start_button
       gosub StartPressed
  if #menubutton = Closed
     set %ENdScript YES
return

;===================================================================
sub DrawMenu
menu Clear
menu Window Title Crisis SOS Fisher 2.0
menu Window Color Black
menu Window Size 186 57
menu Font Transparent #true
menu Font Align Right
menu Font Name MS Sans Serif
menu Font Size 10
menu Font Style
menu Font Color WindowText
menu Font BGColor Lime
menu Button Start_Button 44 12 95 33 Start Fishing
menu Show 421 270
set #menubutton  N/A
return
;===================================================================

sub Pausepressed
  menu delete start
  menu Font Color WindowText
menu Font Style
menu Font Color WindowText
menu Font BGColor Lime
menu Button Start_Button 44 12 95 33 Start Fishing
  set #menubutton  N/A
return
;===================================================================


sub startpressed
  menu delete pause
  menu Font Color WindowText
  menu Font Size 10
  menu Font BGColor Green
  menu Button Pause 44 12 95 33 Pause ; creates new button
  set #menubutton  N/A
  set %StartFishing YES

return


in C2's tutioral the OR means you can do this block of code ... OR you can do this block of code... he probably forgot to seperate into different code blocks when posting....
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 CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 3021
  • Activity:
    3.6%
  • Reputation Power: 41
  • Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +206
  • Referrals: 2
    • View Profile
Re: start/pause buttons for menus
« Reply #4 on: March 03, 2013, 05:45:38 AM »
0
Thank you very much, I am working hard at learning and I greatly appreciate all of your help. I will look through the code and adjust mine. The important thing is that I am reading the lines and trying to understand how they work. My goal is to write a script 100% from scratch.

Return - not sure I completely understand this. Looking through the easyuo documentation, it says that that it is used to return from a sub. Looking at the sub page it says, "You must not jump out of a sub! Use return to properly terminate a sub routine."

Where does it direct the script to? Does it just end it? If I want a sub to loop at times, I still need a return? Thanks!!

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • 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: start/pause buttons for menus
« Reply #5 on: March 03, 2013, 10:02:06 AM »
0
The "return" statement allows the script to return to where the "gosub" was originally called.  You can actually nest "gosubs" such that you might call a subroutine (i.e. gosub) from one sub an then call another one.  Just know that subroutines put their return location on a stack so it will remember the order in which each sub was called.

This sample code will display "This" "thing" "works!" "Deal with it" in order.  See how the code flows.  (notice the gosub called in "FirstSub" and how it returns to the last encountered "gosub" call.  "gosub" return addresses are kept on a stack)

If you understand how this example works, then you can see why you might not want to "goto" to a label outside a subroutine.  Since you have recorded a return location on the stack, but you don't pull that location off the stack in a balanced way, you'll encounter problems when you try to return from a subroutine down the line somewhere, and the script won't behave the way you might expect.

So the golden rule here is, "Always "return" from a "sub" call"

Code: [Select]
gosub Sub1
;script returns here after encountering "return" in Sub1
gosub Sub2
;script returns here after encountering "return" in Sub2
gosub Sub3
;script returns here after encountering "return" in Sub3
stop
;-----------------------------
sub FirstSub
  display Deal with it!
return
;-----------------------------
sub Sub2
  display ok thing
return
;-----------------------------
sub Sub1
  display ok This
return
;-----------------------------
sub Sub3
  display ok works!
  gosub FirstSub
  ;script returns here after encountering "return" in FirstSub
return
« Last Edit: March 03, 2013, 10:16:00 AM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline Neo

  • Prime Program
  • Elite
  • *
  • *
  • Posts: 821
  • Activity:
    0%
  • Reputation Power: 13
  • Neo barely matters.Neo barely matters.
  • Respect: +155
  • Referrals: 3
    • View Profile
Re: start/pause buttons for menus
« Reply #6 on: March 03, 2013, 06:49:52 PM »
0
The "return" statement allows the script to return to where the "gosub" was originally called.  You can actually nest "gosubs" such that you might call a subroutine (i.e. gosub) from one sub an then call another one.  Just know that subroutines put their return location on a stack so it will remember the order in which each sub was called.

This sample code will display "This" "thing" "works!" "Deal with it" in order.  See how the code flows.  (notice the gosub called in "FirstSub" and how it returns to the last encountered "gosub" call.  "gosub" return addresses are kept on a stack)

If you understand how this example works, then you can see why you might not want to "goto" to a label outside a subroutine.  Since you have recorded a return location on the stack, but you don't pull that location off the stack in a balanced way, you'll encounter problems when you try to return from a subroutine down the line somewhere, and the script won't behave the way you might expect.

So the golden rule here is, "Always "return" from a "sub" call"

Code: [Select]
gosub Sub1
;script returns here after encountering "return" in Sub1
gosub Sub2
;script returns here after encountering "return" in Sub2
gosub Sub3
;script returns here after encountering "return" in Sub3
stop
;-----------------------------
sub FirstSub
  display Deal with it!
return
;-----------------------------
sub Sub2
  display ok thing
return
;-----------------------------
sub Sub1
  display ok This
return
;-----------------------------
sub Sub3
  display ok works!
  gosub FirstSub
  ;script returns here after encountering "return" in FirstSub
return
This is a great and yet simple example on how the basic flow of EUO scripts work. Reading through these topics I see several examples like this one that would make the life of a lot of beginners that much easier. We should come up with an index of these or something, for future references!
Never refuse an invitation.
Never resist the unfamiliar.
Never fail to be polite.
And never outstay your welcome.

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 3021
  • Activity:
    3.6%
  • Reputation Power: 41
  • Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +206
  • Referrals: 2
    • View Profile
Re: start/pause buttons for menus
« Reply #7 on: June 15, 2013, 08:31:49 AM »
0
Since I am the OP and I have the time to work on this again, I am going to necro this post!!

I know I am getting close and I know that I am missing something in the commands from the start button to start the fishing sub. When I press start, nothing happens. I am sure it is something small that I have overlooked.

Code: [Select]
;===================================================================
; Script Name: Crisis SOS Chest Fisher
;
; Author: Crisis
; Version: 2.0a
; Shard OSI / FS: OSI
; Release Date: 05/07/2012
; Revision Date: 06/15/2013
; Purpose:
;     Completely automates the operation of fishing up treasure chests when you are in the correct area of your SOS.
;     Works great with Kal In Ex's SOS Master
;
; Features:
;     . Automatically fishes until you fish up a treasure chest. Cuts bones after fishing up chest.
;
; Revisions:
;     . Added bone cutting sub
;     . Cleaned up code
;
; Requirements:
;     . You should be on a boat in the area of your SOS
;     . Must have the SOS in your backpack
;
; Special Thanks:
;     TrailMyx for helping me iron out the kinks and for TrailMyx's Advanced Journal Handler
;     _C2_ for the Menu Tutorial http://www.scriptuo.com/index.php?topic=1535.0
;     Endless Night for helping me fix the issues with the Menu
;===================================================================
;Setup
set %fishingpole XHF_KDF
set %bones BJK_EJK_DJK_YIK_XIK_AJK_ZJK_KJK_FJK_ZIK
set %scissors KAG_JAG
gosub DrawMenu
set %ENDScript NO
set %StartFishing NO
return
;===================================================================

sub CheckMenu
  if #menubutton = Pause
       gosub PausePressed
  if #menubutton = Start
       gosub StartPressed
  if #menubutton = Closed
     set %ENdScript YES
return

;===================================================================

sub DrawMenu
menu Clear
menu Window Title Crisis SOS Fisher 2.0
menu Window Color Black
menu Window Size 186 57
menu Font Transparent #true
menu Font Align Right
menu Font Name MS Sans Serif
menu Font Size 10
menu Font Style
menu Font Color WindowText
menu Font BGColor Lime
menu Button Start 44 12 95 33 Start Fishing
menu Show 421 270
set #menubutton  N/A
return

;===================================================================

sub Pausepressed
  menu delete Pause
  menu Font Color WindowText
menu Font Style
menu Font Color WindowText
menu Font BGColor Lime
menu Button Start 44 12 95 33 Start Fishing
  set #menubutton  N/A
return

;===================================================================

sub startpressed
  menu delete Start
  menu Font Color WindowText
  menu Font Size 10
  menu Font BGColor Green
  menu Button Pause 44 12 95 33 Pause ; creates new button
  gosub TM_AdvJournalSync FISHING
  set #menubutton  N/A
return

;===================================================================

sub TM_AdvJournalSync FISHING
  finditem %fishingpole _C  #CHARID
  if #FINDKIND = -1
  {
    finditem %fishingpole _C #BackpackID
    if #FINDKIND = -1
    display ok How can you fish without your fishing pole?
    halt
    if #FINDKIND = 1
    SOSFishLoop
  }
   SOSFishLoop:
  findItem %fishingpole 1
  set #LObjectID #FindID
  set #LTargetKind 2
  set #LTargetX 0 + #CharPosX
  set #LTargetY 4 + #CharPosY
  event macro 17 0
  target
  event macro 22 0
  set %fishtimeout #SCNT + 9
  target 11s

  gosub TM_AdvJournalScan FISHING VALID_ADVANCE chest_from_the_depths_of_the_ocean
  if #RESULT = #TRUE
  {
    display ARRR!! Thar be me sunken booty!!
    goto EndSOSFishLoop
  }
  goto SOSFishLoop
  {
  EndSOSFishLoop:
  gosub CutBones
  }
  return
 
;===================================================================

sub CutBones
finditem %scissors C_ , #backpackid
if #findcnt > 0
{
  set #lobjectid #findid
  finditem %bones C_ , #backpackid
  while #findcnt > 0
  {
    event macro 17
    target
    set #ltargetid #findid
    set #ltargetkind 1
    event macro 22
    wait 8
    finditem %bones C_ , #backpackid
    if finditem = 0
    halt
  }
}
 return
 
;===================================================================

sub WaitForTargetCursor
set %timeout #scnt + 4
Repeat
      wait %targetcursorwait
      if #scnt > %timeout
         return #false
Until #TARGCURS = 1
return #true
 
;===================================================================

sub TM_AdvJournalGetTrigger
  namespace push
  namespace local TM_AdvJS_ , %1
  set #RESULT !trigger
  namespace pop
  set !TM_FunctionCalled #TRUE
return #RESULT

;===================================================================
; %1 - Journal Name
; %2 - #LPC setting (optional)
; Brings !_jindex up to the most recent #journal entry
sub TM_AdvJournalSync
  namespace push
  namespace local TM_AdvJS_ , %1
  set !_jindex #jindex + 1
  if %0 > 1
    set !lpc_set %2
  namespace pop
  set !TM_FunctionCalled #TRUE
return
;===================================================================
; %1 - Journal Name
; %2 - NONE, ADVANCE , ( _VALID ) - advances jindex pointer, anything else
; %3, %4, %5, etc strings to match
; returns #TRUE for match, #FALSE for no match
;  Will not advance !_jindex pointer to allow for scanning journal history for more than one search.
;  Also searches for : , #SPC in journal entry to be sure someone isn't spamming the text
;  About %2 arguments:
;    NONE: defaults to basic journal scan (no SPAM checking, no #jindex pointer copy advancing)
;    ADVANCE: no spam checking, advances #jindex copy
;    VALID: invokes SPAM filtering, no advance of #jindex copy
;    VALID_ADVANCE, VALIDADVANCE, ADVANCE_VALID, etc.: invokes SPAM filtering, advances of #jindex copy
sub TM_AdvJournalScan
  namespace push
  namespace local TM_AdvJS_ , %1
  set !args %2
  set !temp_lpc #LPC
  if !lpc_set = N/A
    set #LPC 1000
  else
    set #LPC !lpc_set
  set !num_args %0
  set !first_arg 3
  set !sampled_jindex #JINDEX
  if !_jindex = N/A
    set !_jindex !sampled_jindex
  if !charname = N/A
  {
    set !charname #CHARNAME
AdvJournalScan_loop1:
    str pos !charname #SPC
    if #STRRES <> 0
    {
      set !val #STRRES - 1
      str left !charname !val
      set !left #STRRES
      set !val !val + 1
      str del !charname 1 !val
      set !charname !left , _ , #STRRES
      goto AdvJournalScan_loop1
    }
  }
  set !index !first_arg
  repeat
    set !temp_jindex !_jindex
    set !text % . !index
    while !temp_jindex <= !sampled_jindex
    {
      scanjournal !temp_jindex
      str pos #JOURNAL !charname 1
      set !namepos #STRRES
      str count #JOURNAL !charname
      set !namecnt #STRRES
      str pos #JOURNAL :_ 1
      set !smcpos #STRRES
      str pos #JOURNAL !text 1
      set !textpos #STRRES
      if !textpos < !smcpos && !smcpos <> 0 || !smcpos = 1 || :_ notin #JOURNAL || VALID notin !args
        set !pass #TRUE
      else
        set !pass #FALSE
      if ( !text in #journal && ( ( !namepos = 1 && !namecnt <= 1 ) || !pass ) )
      {
        set !temp_jindex !temp_jindex + 1
        if ADVANCE in !args
          set !_jindex !temp_jindex
        set !trigger !text
        set #LPC !temp_lpc
        namespace pop
        set !TM_FunctionCalled #TRUE
        return #TRUE
      }
      set !temp_jindex !temp_jindex + 1
    }
    set !index !index + 1
  until !index - !first_arg > !num_args - !first_arg
  set %10 !sampled_jindex - !_jindex
  set %10 %1 , _ , %10 ; for debugging purposes
  set #LPC !temp_lpc
  set TM_AdvJournalGetTrigger #FALSE
  namespace pop
  set !TM_FunctionCalled #TRUE
return #FALSE

Offline CrisisTopic starter

  • Global Moderator
  • *
  • *
  • Posts: 3021
  • Activity:
    3.6%
  • Reputation Power: 41
  • Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.Crisis is a force to reckon with.
  • Gender: Male
  • Scripting well enough to break things!
  • Respect: +206
  • Referrals: 2
    • View Profile
Re: start/pause buttons for menus
« Reply #8 on: June 16, 2013, 05:58:27 PM »
0
Got it fixed and updated my original script. :)

Tags: