Variable value not updating correctly

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
qwe2112
Posts: 1
Joined: 23 Aug 2016, 20:33

Variable value not updating correctly

23 Aug 2016, 20:48

Hi there,

I'm working on a script to reduce some of the crafting clicking in an RPG. It opens the crafting menu and selects, in order, one of particular companion's skill icons, then the grade box, then a grade, then a crafting mission, and then confirm. It repeats from companions 1-%companions% (skipping companion %skipc%) and then returns.

This is the draft version, so all the clicks are MouseMoves, there are some helpful extra MsgBoxes, and a few things have been commented out (labeled "debug").

It works fine except when I test the skip function. It skips the character totally fine. However, the y-coord of the next skill icon click, %s1y%, should be c1s1y + (compno-1)*sver, but it always returns to the initial %c1s1y% value, despite the compno (companion number) being correct (according to the message box) after the companion skip.

This is my first script and any help would be appreciated!

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.

CoordMode, Mouse, Screen  ; mouse moves to absolute screen coords

;debug section
SendMode Event ;next command doesn't work without it
SetDefaultMouseSpeed, 7 ;for debugging
;SendMode Play ;needs to be activated in the real thing

^\:: ;the hotkey
{

;position-related vars

global c1s1x := 390  ;location of 1st comp's 1st skill icon
global c1s1y := 312

global confirmx = 1752  ;location of confirm button
global confirmy = 871

global gbx := 1693  ;location of grade box
global gby := 256

global m1x := 1766  ;location of 1st mission box
global m1y := 303

global g1x := gbx  ; location of grade 1 button
global g1y := gby+21


global gd := 19.5 ; #px down to next grade
global md := 140 ;#px down to next mission
global shor := 53 ; #px horizontal to next skill icon
global sver := 95 ; #px vertical to next skill icon


;game-related settings
C1Skill := 1  ;1st, 2nd, or 3rd icon
C1Grade := 1  ;grade number
C1Mission := 1  ;works with mission 1-4

C2Skill := 2
C2Grade := 2
C2Mission := 2

C3Skill := 3
C3Grade := 3
C3Mission := 3

C4Skill := 2
C4Grade := 4
C4Mission := 4 

C5Skill := 1
C5Grade := 5
C5Mission := 1 

C6Skill := 1
C6Grade := 6
C6Mission := 1

global companions := 3  ;number of companions
global skipc := 2 ;companion to skip
global compno := 1 ;starts script with companion #compno


;end of settings entry


;main body of script
;Send n  ;open skills pane ;debug

Loop {
 ; setting dummy variables to the correct companion

;skipping section
if compno = %skipc% ; skip companion skipc (need the % signs o/w it doesn't work!!!)
	{
	compno := compno+1
	MsgBox Companion %skipc% skipped.
	MsgBox Compno equals %compno%
	}

else if compno=1 
{
global s1x := c1s1x ;setting the location of the first skill for the selected companion
global s1y := c1s1y
	g := C1Skill
	h := C1Grade
	j := C1Mission
	}
else if compno=2 
{
global s1x := c1s1x
global s1y := c1s1y + (compno-1)*sver ;setting the location of the first skill for the selected companion

	g := C2Skill
	h := C2Grade
	j := C2Mission
	}
else if compno=3 
{
global s1x := c1s1x	
global s1y := c1s1y + (compno-1)*sver ;setting the location of the first skill for the selected companion
	g := C3Skill
	h := C3Grade
	j := C3Mission
	}
else if compno=4 
{
global s1x := c1s1x
global s1y := c1s1y + (compno-1)*sver ;setting the location of the first skill for the selected companion
	g := C4Skill
	h := C4Grade
	j := C4Mission
	}
else if compno=5 
{
;Click WheelDown ;debug
global s1x := c1s1x
global s1y := c1s1y + (compno-2)*sver ;setting the location of the first skill for the selected companion
	g := C5Skill
	h := C5Grade
	j := C5Mission
	}
else if compno=6 
{
;Click WheelDown ;debug
global s1x := c1s1x
global s1y := c1s1y + (compno-2)*sver ;setting the location of the first skill for the selected companion
	g := C6Skill
	h := C6Grade
	j := C6Mission
	}
else 
{ 
MsgBox Error assigning compno to dummies
ExitApp
}

selectSkill(g) ; select skill
selectGrade(h)  ; select grade
selectMission(j) ; select mission
MouseMove confirmx,confirmy  ; confirmn
;Click ;debug
compno := compno+1
} Until compno = companions + 1  ;checking if everyone finished

MsgBox Compno equals %compno%
Return

selectSkill(w) {
if w < 4
	MouseMove s1x+shor*(w-1),s1y  ;MouseMove second icon
else 
	{
	MsgBox Skill type undefined.
	ExitApp
	}
}

selectGrade(x) {
MouseMove gbx,gby  ;open grade menu
if x<10
	MouseMove g1x,g1y+gd*(x-1) ;select grade 2 etc.
else 
	{
	MsgBox Grade number undefined.
	ExitApp
	}
}

selectMission(y) {
if y<5
	MouseMove m1x,m1y+md*(y-1)  ;select grade 2 etc.
else
	{
	MsgBox Mission number undefined.
	ExitApp
	}
}
}
foxhunter
Posts: 72
Joined: 04 Aug 2016, 04:27

Re: Variable value not updating correctly

24 Aug 2016, 14:34

Add a continue in this if clause:

Code: Select all

if compno = %skipc% ; skip companion skipc (need the % signs o/w it doesn't work!!!)
	{
	compno := compno+1
	MsgBox Companion %skipc% skipped.
	MsgBox Compno equals %compno%
	continue  ; add here this continue statement
	}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Fredrik F, garry, maxkill, RandomBoy, ShatterCoder and 415 guests