using send with variables that have curly brackets

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Zenyatta
Posts: 6
Joined: 19 Aug 2018, 23:19

using send with variables that have curly brackets

19 Aug 2018, 23:44

Hello, I'm very new to this, but I've been trying to learn how to do things. I'm trying to make a script that sends something to a notepad on a loop, that has variables that increase, However the text that I am trying to send contains curly brackets so i'm assuming that it's just going to mess with the syntax of everything as you will be able to see in the code below, so I thought that I would use SendRaw, or send, {blind} The variable is the {color:16646144}". The rest of the code stays the same basically

So basically I want the variable to increase until it reaches a certain number then stop, until then it loops sending the text with the increasing variable and pressing enter.
How can I go about doing this?

Code: Select all

/give @p leather_helmet 1 0 {display:{color:16646144},AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:99999999,Operation:0,UUIDMost:33219,UUIDLeast:246050},{AttributeName:"generic.followRange",Name:"generic.followRange",Amount:99999999,Operation:0,UUIDMost:91172,UUIDLeast:432987},{AttributeName:"generic.knockbackResistance",Name:"generic.knockbackResistance",Amount:99999999,Operation:0,UUIDMost:855,UUIDLeast:502501},{AttributeName:"generic.attackDamage",Name:"generic.attackDamage",Amount:99999999,Operation:0,UUIDMost:24782,UUIDLeast:359227}]}
Rohwedder
Posts: 7644
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: using send with variables that have curly brackets

20 Aug 2018, 01:02

Hallo,
these seem to be Minecraft Commands. You're in the wrong forum!
Zenyatta
Posts: 6
Joined: 19 Aug 2018, 23:19

Re: using send with variables that have curly brackets

20 Aug 2018, 01:37

Rohwedder wrote:Hallo,
these seem to be Minecraft Commands. You're in the wrong forum!
They are! However it doesn't really matter, considering it's more about getting around the issue with the curly bracket, and the variable and since they use curly brackets in some places, and I'm wanting to use AHK for my script that's why i'm asking my question here.
Perhaps you can direct me somewhere else, if you're suggesting this is the wrong place?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: using send with variables that have curly brackets

20 Aug 2018, 04:22

using Format, replace the variables u wanna change with {1:}, {2:} and so on..
traditional assignment used here to avoid having to escape chars.
also send isnt really meant for long strings, use ctr+v or other means, otherwise itd be slow kinda

Code: Select all

command = /give @p leather_helmet 1 0 {display:{color:{1:}},AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:99999999,Operation:0,UUIDMost:33219,UUIDLeast:246050},{AttributeName:"generic.followRange",Name:"generic.followRange",Amount:99999999,Operation:0,UUIDMost:91172,UUIDLeast:432987},{AttributeName:"generic.knockbackResistance",Name:"generic.knockbackResistance",Amount:99999999,Operation:0,UUIDMost:855,UUIDLeast:502501},{AttributeName:"generic.attackDamage",Name:"generic.attackDamage",Amount:99999999,Operation:0,UUIDMost:24782,UUIDLeast:359227}]}
;                                                     ^^^^ - format() 

Loop 10
{
	colorID := 16646144 + A_Index
	Clipboard := Format(command, colorID)
	Send ^v
}
Zenyatta
Posts: 6
Joined: 19 Aug 2018, 23:19

Re: using send with variables that have curly brackets

21 Aug 2018, 08:33

swagfag wrote:using Format, replace the variables u wanna change with {1:}, {2:} and so on..
traditional assignment used here to avoid having to escape chars.
also send isnt really meant for long strings, use ctr+v or other means, otherwise itd be slow kinda

Code: Select all

command = /give @p leather_helmet 1 0 {display:{color:{1:}},AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:99999999,Operation:0,UUIDMost:33219,UUIDLeast:246050},{AttributeName:"generic.followRange",Name:"generic.followRange",Amount:99999999,Operation:0,UUIDMost:91172,UUIDLeast:432987},{AttributeName:"generic.knockbackResistance",Name:"generic.knockbackResistance",Amount:99999999,Operation:0,UUIDMost:855,UUIDLeast:502501},{AttributeName:"generic.attackDamage",Name:"generic.attackDamage",Amount:99999999,Operation:0,UUIDMost:24782,UUIDLeast:359227}]}
;                                                     ^^^^ - format() 

Loop 10
{
	colorID := 16646144 + A_Index
	Clipboard := Format(command, colorID)
	Send ^v
}
So If I add another variable to this, eg {2}, would I need to add another line of code like colourID, such as "amount" or something? Eg:

Code: Select all

command = /give @p leather_helmet 1 0 {display:{color:{1:}},AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:{2:},Operation:0,UUIDMost:33219,UUIDLeast:246050},{AttributeName:"generic.followRange",Name:"generic.followRange",Amount:{2:},Operation:0,UUIDMost:91172,UUIDLeast:432987},{AttributeName:"generic.knockbackResistance",Name:"generic.knockbackResistance",Amount:{2:},Operation:0,UUIDMost:855,UUIDLeast:502501},{AttributeName:"generic.attackDamage",Name:"generic.attackDamage",Amount:{2:},Operation:0,UUIDMost:24782,UUIDLeast:359227}]}
;                                                     ^^^^ - format() 

Loop 10
{
	colorID := 16646144 + A_Index
	amount := 16646145 + A_Index
	Clipboard := Format(command, colorID, amount)
	Send ^v
}
Or am I misunderstanding what you're trying to say?
Last edited by Zenyatta on 21 Aug 2018, 08:52, edited 1 time in total.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: using send with variables that have curly brackets

21 Aug 2018, 08:51

yeah but the syntax is {1:}, {2:}, {3:} with the semi-colon
normally simply {} would suffice, but u already have braces in your string and this could lead to a situation outlined in the docs:
Use {{} and {}} to include literal braces in the string. Any other invalid placeholders are included in the result as is.
Zenyatta
Posts: 6
Joined: 19 Aug 2018, 23:19

Re: using send with variables that have curly brackets

21 Aug 2018, 08:56

swagfag wrote:yeah but the syntax is {1:}, {2:}, {3:} with the semi-colon
normally simply {} would suffice, but u already have braces in your string and this could lead to a situation outlined in the docs:
Use {{} and {}} to include literal braces in the string. Any other invalid placeholders are included in the result as is.
Yeah that's my bad, I accidentally left it out when I edited it, but realised soon after. Since it wasn't working!
Thank you so much for helping me put together this random code :lol: It's a good learning experience.

Edit: Ah I see, thanks for the explanation!
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: using send with variables that have curly brackets

23 Aug 2018, 04:53

theres a 16383 character limit per line. break up your command into several parts and concatenate them back together at the end. SendInput has a 5k character limit, the other send modes probably dont, but u shouldnt be sending the command character by character in the first place. If Format() is breaking the 16k character limit, split on a comma and continue on the next line.

Code: Select all

command := "/give @p leather_helmet 1 0 "
json =
(LTrim Join
{
	display:
	{
		color:{1:}
	},
	AttributeModifiers:
	[
		{
			AttributeName:"generic.maxHealth",
			Name:"generic.maxHealth",
			Amount:{2:},
			Operation:0,
			UUIDMost:33219,
			UUIDLeast:246050
		},
		{
			AttributeName:"generic.followRange",
			Name:"generic.followRange",
			Amount:{2:},
			Operation:0,
			UUIDMost:91172,
			UUIDLeast:432987
		},
		{
			AttributeName:"generic.knockbackResistance",
			Name:"generic.knockbackResistance",
			Amount:{2:},
			Operation:0,
			UUIDMost:855,
			UUIDLeast:502501
		},
		{
			AttributeName:"generic.attackDamage",
			Name:"generic.attackDamage",
			Amount:{2:},
			Operation:0,
			UUIDMost:24782,
			UUIDLeast:359227
		}
	]
}
)
command .= json

Loop 10
{
	colorID := 16646144 + A_Index
	amount := 16646145 + A_Index
	Clipboard := Format(command
					, colorID
					, amount)
	Send ^v
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Panaku, Rohwedder, roysubs and 310 guests