Results 1 to 1 of 1

Thread: Go2 adjustment to deal with the commas.

  1. #1

    Default Go2 adjustment to deal with the commas.

    Old code:

    Code:
    check_silvers = proc {
    	hook_proc = proc { |server_string|
    		if server_string =~ /^\s*Name\:|^\s*Gender\:|^\s*Normal \(Bonus\)|^\s*Strength \(STR\)\:|^\s*Constitution \(CON\)\:|^\s*Dexterity \(DEX\)\:|^\s*Agility \(AGI\)\:|^\s*Discipline \(DIS\)\:|^\s*Aura \(AUR\)\:|^\s*Logic \(LOG\)\:|^\s*Intuition \(INT\)\:|^\s*Wisdom \(WIS\)\:|^\s*Influence \(INF\)\:/
    			nil
    		elsif server_string =~ /^\s*Mana\:\s+\-?[0-9]+\s+Silver\:\s+([0-9]+)/
    			DownstreamHook.remove('go2_check_silvers')
    			nil
    		else
    			server_string
    		end
    	}
    	clear
    	DownstreamHook.add('go2_check_silvers', hook_proc)
    	silence_me unless undo_silence = silence_me
    	put 'info'
    	silence_me if undo_silence
    	while (line = get)
    		if line =~ /^\s*Mana\:\s+\-?[0-9]+\s+Silver\:\s+([0-9]+)/
    			silvers = $1.to_i
    			break
    		end
    	end
    	silvers
    }

    Updated code:

    Code:
    check_silvers = proc {
    	hook_proc = proc { |server_string|
    		if server_string =~ /^\s*Name\:|^\s*Gender\:|^\s*Normal \(Bonus\)|^\s*Strength \(STR\)\:|^\s*Constitution \(CON\)\:|^\s*Dexterity \(DEX\)\:|^\s*Agility \(AGI\)\:|^\s*Discipline \(DIS\)\:|^\s*Aura \(AUR\)\:|^\s*Logic \(LOG\)\:|^\s*Intuition \(INT\)\:|^\s*Wisdom \(WIS\)\:|^\s*Influence \(INF\)\:/
    			nil
    		elsif server_string =~ /^\s*Mana\:\s+\-?[0-9]+\s+Silver\:\s+(.*)/
    			DownstreamHook.remove('go2_check_silvers')
    			nil
    		else
    			server_string
    		end
    	}
    	clear
    	DownstreamHook.add('go2_check_silvers', hook_proc)
    	silence_me unless undo_silence = silence_me
    	put 'info'
    	silence_me if undo_silence
    	while (line = get)
    		if line =~ /^\s*Mana\:\s+\-?[0-9]+\s+Silver\:\s+(.*)/
    			silvers = $1.gsub(",","").to_i
    			break
    		end
    	end
    	silvers
    }
    Updated the regex to take everything after silvers instead of just the numbers before the first comma, then gsub out the commas.

    Changes in 3 places.
    - 2 where it changes from s+([0-9]+) to s+(.*)
    - 1 where the change is from silvers = $1.to_i to silvers = $1.gsub(",","").to_i
    Last edited by Sadrael; 10-11-2020 at 05:59 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •