Unwanted new line

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Vadanite
Posts: 4
Joined: 30 Nov 2021, 04:02

Unwanted new line

Post by Vadanite » 30 Nov 2021, 04:22

I'm trying to create a script that results in a randomised word separated by an underscore, with randomised numbers from 1 - 9999. I have an issue in which I have an unwanted new line, and I don't know how to add an underscore to separate these two terms. Any help would be appreciated, thank you :)

Code: Select all

NumpadDiv::

SetKeyDelay, 0, 70
ControlSend, , t/unnick{Enter}, A

fileread, list, nouns.txt
noun := strsplit(list, "`r")

random,rdm,1,noun.Length()
var1 := noun[rdm],1
Random, var2, 1, 9999
var1 .= var2

StringReplace, var1, var1,`r`n,, All ; Attempt at trying to fix enter issue.

ControlSend, , t/nick%var1%{Enter}, A
return
Output:
t/unnick
t/nick
bowl198

Desired Output:

t/unnick
t/nick bowl_198

Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Unwanted new line

Post by Rohwedder » 30 Nov 2021, 05:38

Hallo,
only a try. Replace:

Code: Select all

noun := strsplit(list, "`r")
with:

Code: Select all

noun := strsplit(list, ["`n","`r"])

Vadanite
Posts: 4
Joined: 30 Nov 2021, 04:02

Re: Unwanted new line

Post by Vadanite » 30 Nov 2021, 07:08

Rohwedder wrote:
30 Nov 2021, 05:38
Hallo,
only a try. Replace:

Code: Select all

noun := strsplit(list, "`r")
with:

Code: Select all

noun := strsplit(list, ["`n","`r"])
After some minor adjustments, including this line you gave me, I've ironed most of the issues :)

However, a small issue has presented itself.. The script only sometimes has the word in front of the _(numbers). Here's an example of 3 outputs:

/unnick
/nick following_9126
/unnick
/nick _9257 <-- Should not output this
/unnick
/nick task_9648

This is what the code looks like currently:

Code: Select all

NumpadDiv::

SetKeyDelay, 0, 60
ControlSend, , /unnick{Enter}, A

fileread, list, nouns.txt
noun := strsplit(list, ["`n","`r"])

random,rdm,1,noun.Length()
var1 := noun[rdm],1
Random, var2, 1, 9999
var1 .= "_" + var2

StringReplace, var1, var1,`r`n,, All

ControlSend, , /nick{Space}, A
ControlSend, , %var1%{Enter}, A
return

^r::Reload

Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Unwanted new line

Post by Rohwedder » 30 Nov 2021, 10:08

Then with:

Code: Select all

noun := strsplit(list, ["`r`n","`n","`r"])

Vadanite
Posts: 4
Joined: 30 Nov 2021, 04:02

Re: Unwanted new line

Post by Vadanite » 30 Nov 2021, 11:05

It works :) Thank you very much Rohwedder. I have added some other lines to the code in order to accomodate other features. Here is the full code for future reference to anyone else struggling with the same issue:

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%  ; Ensures a consistent starting directory.
/* Description
Written By: Zain
Date Started: 28/11/2021
Last Edit: 28/11/2021

Program Description:
This is a script that automatically creates a random nick on Jartex.
IMPORTANT: This must be ran as admin for it to work on Minecraft!
Rand is just a file with random stuff people write in their names like XD.
*/
NumpadDiv::

SetKeyDelay, 0, 60
ControlSend, , t/unnick{Enter}, A

fileread, list, nouns.txt
noun := strsplit(list, ["`r`n","`n","`r"])

random,rdm,1,noun.Length()
var1 := noun[rdm],1

fileread, list, rand.txt
rand := strsplit(list, ["`r`n","`n","`r"])

random,rdm,1,rand.Length()
rand1 := rand[rdm],1

StringReplace, var1, var1,`r`n,, All
StringReplace, rand1, rand1,`r`n,, All

Random, var2, 1, 9999
var1 .= rand1 .= var2
nick := SubStr(var1, 1, 16) ; Caps the number of characters to 16

ControlSend, , t/nick{Space}, A
ControlSend, , %nick%{Enter}, A

sleep 200

Click
return

^r::Reload

Post Reply

Return to “Ask for Help (v1)”