Variables in quotation marks Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
NewbieITguy
Posts: 8
Joined: 21 Jun 2021, 09:49

Variables in quotation marks

23 Jun 2021, 13:33

I've been looking for a solution to this, but nothing is standing out.

I have this code here:

Code: Select all

TellmeMore("pancakes")


TellmeMore(Message)
	{
	CoordMode Pixel
	WatchCursor:
	ToolTip, "%Message%"
	return
	}
This is a snippet. I wanted to have a function where I can pass an argument of whatever message I wanted into the function.

The problem I'm having is that when I run this, the tooltip pops up with:
image.png
image.png (1.16 KiB) Viewed 860 times
That isn't showing my message at all! I put in pancakes as an example, but yeah, it's never showing the words I want. Would anyone mind helping me with this?
doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Re: Variables in quotation marks

23 Jun 2021, 14:02

Code: Select all


tooltip, % """" Message """"

it takes a lot of quote marks lol

edit: this works too i think...

Code: Select all

tooltip, `"%Message%`"
NewbieITguy
Posts: 8
Joined: 21 Jun 2021, 09:49

Re: Variables in quotation marks

23 Jun 2021, 14:10

doubledave22 wrote:
23 Jun 2021, 14:02

Code: Select all


tooltip, % """" Message """"

it takes a lot of quote marks lol

edit: this works too i think...

Code: Select all

tooltip, `"%Message%`"

Thanks!

Here's my new code:

Code: Select all

TellmeMore("pancakes")

TellmeMore(Message)
	{
	CoordMode Pixel
	WatchCursor:
	ToolTip, `"%Message%`"
	return
	}
	
I still get
image.png
image.png (1.23 KiB) Viewed 835 times
:(
Last edited by gregster on 23 Jun 2021, 14:23, edited 1 time in total.
Reason: This post was approved after the next three posts were already made.
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Variables in quotation marks

23 Jun 2021, 14:11

doubledave22 wrote: edit: this works too i think...

Code: Select all

tooltip, `"%Message%`"
The backticks aren’t necessary:

Code: Select all

Message = Hello
MsgBox, "%Message%"
(works with ToolTip, too)
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Variables in quotation marks

23 Jun 2021, 14:17

@NewbieITguy - It should work. That must not be the full script since it would end right away (and as you said, it is a snippet), so you must have something else going on. Run the following as a stand-alone script to show it works:

Code: Select all

#Persistent
TellmeMore("pancakes")
return

TellmeMore(Message)
	{
	CoordMode Pixel
	WatchCursor:
	ToolTip, "%Message%"
	return
	}
(some unneeded lines left in the above script to show they’re also not the issue)
Last edited by boiler on 23 Jun 2021, 14:20, edited 1 time in total.
doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Re: Variables in quotation marks

23 Jun 2021, 14:19

oh whoops, I assumed his example didn't work without even testing.

I ran his code and I am seeing "pancakes"

perhaps it's something else?

Code: Select all

^t::
msg = pancakes 
;msg := "pancakes" ; this works too
TellmeMore(msg)
return

TellmeMore(Message)
{
	CoordMode Pixel
	WatchCursor:
	ToolTip, "%Message%"
	return
}
you probably need to post more of the code since what you posted does actually work. it's probably the variable you are sending as the message (see above for examples)
NewbieITguy
Posts: 8
Joined: 21 Jun 2021, 09:49

Re: Variables in quotation marks

23 Jun 2021, 14:26

boiler wrote:
23 Jun 2021, 14:17
@NewbieITguy - It should work. That must not be the full script since it would end right away (and as you said, it is a snippet), so you must have something else going on. Run the following as a stand-alone script to show it works:

Code: Select all

#Persistent
TellmeMore("pancakes")
return

TellmeMore(Message)
	{
	CoordMode Pixel
	WatchCursor:
	ToolTip, "%Message%"
	return
	}
(some unneeded lines left in the above script to show they’re also not the issue)
Sure, here's the full code. I'm not sure what's messing with what.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%\Data  ; Ensures a consistent starting directory.


#Persistent
SetTimer, WatchCursor, 100
TellmeMore("pancakes")
return

/*
#c::
	clipboard := ""
	ClipWait
	clipboard := clipboard
	Assetname := clipboard
	clipboard := ""
	ClipWait
	clipboard := clipboard
	Issue := clipboard
	return
	
#v::
	Send %Assetname% - "%Issue%"
	return

*/

TellmeMore(Message)
	{
	CoordMode Pixel
	WatchCursor:
	toolTip, "%Message%"
	return
	}




^Esc::ExitApp
Now, what I did notice is that, for a split second, it shows "pancakes". Then it goes back to an empty string.
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Variables in quotation marks  Topic is solved

23 Jun 2021, 14:33

Make the ToolTip display a static variable so its value persists each time the code at the label is executed:

Code: Select all

TellmeMore(Message)
	{
	static msg
	msg := Message
	CoordMode Pixel
	WatchCursor:
	toolTip, "%msg%"
	return
	}
NewbieITguy
Posts: 8
Joined: 21 Jun 2021, 09:49

Re: Variables in quotation marks

23 Jun 2021, 16:51

boiler wrote:
23 Jun 2021, 14:33
Make the ToolTip display a static variable so its value persists each time the code at the label is executed:

Code: Select all

TellmeMore(Message)
	{
	static msg
	msg := Message
	CoordMode Pixel
	WatchCursor:
	toolTip, "%msg%"
	return
	}
Perfect, just what I needed. Now I got a code that works just the way I want!

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%\Data  ; Ensures a consistent starting directory.


#Persistent
SetTimer, WatchCursor, 100
return


#c::
	TellmeMore("Coppy asset tag")
	clipboard := ""
	ClipWait
	clipboard := clipboard
	Assetname := clipboard
	clipboard := ""
	TellmeMore("Copy issue")
	ClipWait
	clipboard := clipboard
	Issue := clipboard
	TellmeMore("Windowskey V to paste")
	return
	
#v::
	Send %Assetname% - "%Issue%"
	return



TellmeMore(Message)
	{
	static msg
	msg := Message
	CoordMode Pixel
	WatchCursor:
	toolTip, %msg%
	return
	}




^Esc::ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 359 guests