Varable not asigned a value?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Varable not asigned a value?

Post by PepeLapiu » 27 Jan 2022, 00:45

So I get this warning that the variable was not assigned a value. It's got to be an other stoopit syntax mistake I can't see. Maybe you can?

Code: Select all

CHATHODL(ByRef tex,ByRef wor,ByRef restart_chat)
{
	restart_chat := "false"
	Send, ^0
	SetDefaultMouseSpeed, 2
	Click,1733,302
	ImageSearch,x_send,y_send,1449,780,1660,1133, ff_hodl_chat_send.png
	VarChat := 0
	While (ErrorLevel =1)
	{
		If VarChat >= 30
			Msgbox, Chat Send button not found
		Sleep, 100
		ImageSearch,x_send,y_send,1449,780,1660,1133, ff_hodl_chat_send.png
		If (ErrorLevel = 1)
			Click,1787,1128
		VarChat++
	}
	x_chat := (x_send - 75)
	y_chat := (y_send - 42)
	x_bottom := (x_send + 75)
	y_bottom := (y_send - 120)
	x_top := (x_send - 475)
	y_top := (y_send - 800)
	x_click := (x_send - 465)
	y_click := (y_send - 810)
	x_send := (x_send + 30)
	clipboard := "nothing"
	Click, %x_chat%, %y_chat%
	Send, % tex
	Sleep, 200
	Click, %x_send%, %y_send%
	Sleep, 200
	Click Left Down,%x_bottom%, %y_bottom%
	Sleep, 100
	Click Left Up, %x_top%, %y_top%
	MouseMove, x_click,y_click
	Sleep, 100
	Send, ^c
	Sleep, 100
	If (InStr(Clipboard, wor) = 0)
		restart_chat := "true"
	SetDefaultMouseSpeed, 2
	
}


tex := % "PepeBot says: Hi there " user_name ". Give me a second to gather some information."
wor := "gather"
CHATHODL(tex,wor,"false")
If (restart_chat = "true")
	Goto, CHAT_RESTART
Once it gets to the If (restart_chat = "true") line, it pulls a variable with no value warning. Why?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Varable not asigned a value?

Post by swagfag » 27 Jan 2022, 02:13

u already know the why. the warning told u that clearly. its because at that point in time ure trying to compare the uninitialized global variable restart_chat against something

u probably meant to pass the variable to the byref function. instead ure passing the string "false"

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: Varable not asigned a value?

Post by PepeLapiu » 27 Jan 2022, 12:20

swagfag wrote:
27 Jan 2022, 02:13
u already know the why. the warning told u that clearly. its because at that point in time ure trying to compare the uninitialized global variable restart_chat against something

u probably meant to pass the variable to the byref function. instead ure passing the string "false"
I already figured it out. If I just pass to the function like this: CHATHODL(tex,wor,restart_chat) than it works just fine.
But I don't understand why passing into the function a string doesn't work, but a var with a string value in it works.

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Varable not asigned a value?

Post by boiler » 27 Jan 2022, 12:29

It either because you're not showing the line you have added before this line:

Code: Select all

CHATHODL(tex,wor,restart_chat)
...which would be something like:

Code: Select all

restart_chat := "false"
And doing so initializes the global variable restart_chat.

...or because you used a variable instead of text, which is what swagfag pointed out that you didn't do previously, you have linked the variable to the one in the function via the ByRef. When you passed a literal string, there is no tie-in between the variables.

Post Reply

Return to “Ask for Help (v1)”