Pretty plain and simple, I'm trying to terminate the script with the ESC key and it won't terminate when running Path(). I've tried putting the HotKeySet definitions in the Path()function and still didn't work. I'm new to AutoIt.
; Press Esc to terminate script, Pause/Break to "pause"
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
; Start Pathing
MsgBox(0,"Starting...","Will Start 2 seconds after you close this.")
Sleep(2000)
Path()
Func Path()
Opt("SendKeyDownDelay", 500)
$pathing = True
$i = 0
$j = 5 ; Only here to prevent an infinite loop because HotKeySet won't terminate on ESC
While $i < $j
Send("{A}")
Send("{S}")
Send("{W}")
Send("{D}")
$i = $i + 1
WEnd
EndFunc
Func CheckForBattle()
Return True
EndFunc
Func TogglePause()
$Paused = Not $Paused
While $Paused
Sleep(100)
ToolTip('Script is "Paused"', 0, 0)
WEnd
ToolTip("")
EndFunc
Func Terminate()
Exit 0
EndFunc
Func ShowMessage()
MsgBox(4096, "", "This is a message.")
EndFunc
I guess it is because you are sending capital letters. This leads to shift is held for 500ms. You have to either press shift ESC during that time or set another hotkey like this:
; Press Esc to terminate script, Pause/Break to "pause"
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+{ESC}", "Terminate")
; Start Pathing
MsgBox(0, "Starting...", "Will Start 2 seconds after you close this.")
Sleep(2000)
Path()
Func Path()
Opt("SendKeyDownDelay", 500)
$pathing = True
$i = 0
$j = 5 ; Only here to prevent an infinite loop because HotKeySet won't terminate on ESC
While $i < $j
Send("A")
Send("S")
Send("W")
Send("D")
$i = $i + 1
WEnd
EndFunc ;==>Path
Func CheckForBattle()
Return True
EndFunc ;==>CheckForBattle
Func TogglePause()
$Paused = Not $Paused
While $Paused
Sleep(100)
ToolTip('Script is "Paused"', 0, 0)
WEnd
ToolTip("")
EndFunc ;==>TogglePause
Func Terminate()
Exit 0
EndFunc ;==>Terminate
Func ShowMessage()
MsgBox(4096, "", "This is a message.")
EndFunc ;==>ShowMessage
Related
what i want to do is when a button is pressed (in Startergui.ExitGUI.ExitBtn) it decreases a variable value (for me it is "seatsOccupied") by 1. I want to also make it so that if seatsOccupied = 0 then it changes the playercount.text and countdown.text to: playercount.text = "0 / 10" and countdown.text = "Waiting for players.." but i know how to do that.
main script:
seatsOccupied = 0
textLabel = game.Workspace.TruckLanes.InvisibleSurfaceGui.BillboardGui.Frame.TextLabel
playercount = game.Workspace.TruckLanes.InvisibleSurfaceGui.BillboardGui.Frame.Countdown
countdown = 15
signtext = game.Workspace.TruckLanes.Lane2.Sign.Top.SurfaceGui.TextLabel
local TeleportService = game:GetService("TeleportService")
truckSeats = script.Parent.Parent.Truck.Seats:GetChildren() -- define truckSeats here
playercount.Text = "Players: 0 / 10"
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
for i, seat in pairs(truckSeats) do -- use the truckSeats variable here
if not seat.Occupant then
seat:Sit(player.Character.Humanoid)
seatsOccupied = seatsOccupied + 1
playercount.Text = "Players: " .. seatsOccupied .. "/" .. #truckSeats
player.Character.Humanoid.JumpPower = 0
game.ReplicatedStorage.ShowExitGUI:FireClient(player)
for i = 15,0 -1 do
game.Workspace.TruckLanes.InvisibleSurfaceGui.BillboardGui.TextLabel.Text = "Leaving in " ..i.." seconds"
end
for i = 15, 0, -1 do
textLabel.Text = "Leaving in " .. i .. " seconds"
signtext.Text = "Leaving in " .. i .. " seconds"
wait(1)
end
-- Move truck
-- Reserve server
local players = {}
for i, v in pairs(game.Workspace.TruckLanes.Lane2.Truck.Seats:GetChildren()) do
if v.Occupant then
print("Occupant found. " .. v.Parent.Name)
table.insert(players, game.Players:GetPlayerFromCharacter(v.Occupant.Parent))
end
end
if #players > 0 then
for i = 0, 150, 1 do -- Change 30 to number of studs
script.Parent.Parent.Truck:TranslateBy(script.Parent.Parent.Truck.Hitbox.CFrame.lookVector)
wait(0.01)
end
for i = 0, 150, 1 do -- Change 30 to number of studs
script.Parent.Parent.Truck:TranslateBy(-script.Parent.Parent.Truck.Hitbox.CFrame.lookVector)
wait(0.01)
end
local serverData = TeleportService:ReserveServer(12433394609)
TeleportService:TeleportToPrivateServer(12433394609, serverData, players)
for i = 0, 150, 1 do -- Change 30 to number of studs
script.Parent.Parent.Truck:TranslateBy(-script.Parent.Parent.Truck.Hitbox.CFrame.lookVector)
wait(0.01)
end
textLabel.Text = "Waiting For Players.."
playercount.Text = "0 / 10"
end
end
end
end
end)
-- WHERE I DO NOT KNOW WHAT TO DO/WHY ITS NOT WORKING
button = game.StarterGui.ExitGUI.ExitBtn.MouseButton1Click
local function onExitButtonClicked()
if seatsOccupied > 0 then
seatsOccupied = seatsOccupied - 1
playercount.Text = "Players: " .. seatsOccupied .. "/" .. #truckSeats
if seatsOccupied == 0 then
textLabel.Text = "Waiting For Players.."
playercount.Text = "0 / " .. #truckSeats
end
end
end
button:Connect(onExitButtonClicked)
Second script (localscript) that tells the button to do stuff
local clicked = game.ReplicatedStorage.LeaveTruck:FireServer()
-- Connect the function to the ShowExitGUI event
game.ReplicatedStorage.ShowExitGUI.OnClientEvent:Connect(function()
script.Parent.ExitBtn.Visible = true
end)
ExitButtonClicked = function()
print("Exit button clicked")
game.ReplicatedStorage.LeaveTruck:FireServer()
script.Parent.ExitBtn.Visible = false
print("its trueeeeeee")
end
-- Connect the function to the ExitBtn's MouseButton1Click event
script.Parent.ExitBtn.MouseButton1Click:Connect(ExitButtonClicked)
Hierarchy: First script: game -> workspace -> trucklanes -> lane2 -> lane2detector -> detectorscript Second script: game -> starterGui -> exitgui -> ClientExit (Aka the script) the button: game -> startergui -> exitgui -> ExitBtn (aka the button)
I tried the above scripts, but they don't work. I was expecting to: contact with the border seat the player countdown from 15 seconds and a player count -- where it doesn't work when the player presses the leave/exitbtn, it decreases the seatsoccupied value by 1, and when the value is 0, it changes the playercount.text and countdown.text to: "0/10" and "Waiting for players.."
Using Mitsubishi's RT Toolbox3 and Melfa Basic VI programming language, I am trying to get the syntax correct for an If...Then...Elseif...Endif statement.
I would like this robot to assess 3 external Inputs and based on their state run different Subroutines. If none of these inputs are true I want the robot to go to a "Waiting" position, we'll label this position posXXX.
Here is what is currently running in this robot. This script selects the proper subroutine but doesn't account for the condition when none of the inputs are true. When I attempt to insert the "Else" Goto posXXX I get syntax errors.
If M_In(11) = 1 Then *Box1
If M_In(12) = 1 Then *Box2
If M_In(13) = 1 Then *Box3
Thank you.
Below is the script that resolved my question.
*BoxEval
Mvs posPostScan
If M_In(10) = 1 Then
GoSub *Box6
Break
ElseIf M_In(11) = 1 Then
GoSub *Box1
Break
ElseIf M_In(12) = 1 Then
GoSub *Box2
Break
ElseIf M_In(13) = 1 Then
GoSub *Box3
Break
ElseIf M_In(14) = 1 Then
GoSub *Box4
Break
ElseIf M_In(15) = 1 Then
GoSub *Box5
Break
Else
GoSub *BoxEval
EndIf
Why the main thread doesn't continue to run when the other thread yield?
You see there is no "hello world" on the terminal.
function foo ()
print("foo" )
count = 0;
while( 0<1 )
do
count = count + 1;
print("count=", count);
if count>5 then
break
end
end
return coroutine.yield()
end
co = coroutine.create(function ()
foo();
print("hello world") --why doesn't "hello world" output to the terminal?
print(type(co))
return b, "end"
end)
coroutine.resume(co)
ADDED:
This code snippet(adding one line code) seems work,but I don't fully understand why.
function foo ()
print("foo" )
count = 0;
while( 0<1 )
do
count = count + 1;
print("count=", count);
if count>5 then
break
end
end
return coroutine.yield()
end
co = coroutine.create(function ()
foo();
print("hello world")
print(type(co))
return b, "end"
end)
coroutine.resume(co)
coroutine.resume(co) --add this line
There is no "hello world" in the console because the coroutine yields befor it is printed.
co = coroutine.create(function ()
foo(); -- <-- coroutine.yield() inside!
print("hello world")
print(type(co))
return b, "end"
end)
Your coroutine calls foo() befor print("hello world"). Inside foo you call coroutine.yield.
Therefor your single coroutine.resume returns and your program is done.
Adding a second coroutine.resume(co) will make co continue where it yielded and hence start from print("hello world")
I have the following "input.file":
10 61694 rs546443136 T G . PASS RefPanelAF=0.0288539;AC=0;AN=1186;INFO=1.24991e-09 GT:DS:GP 0/0:0.1:0.9025,0.095,0.0025 0/0:0.1:0.9025,0.095,0.0025 0/0:0.1:0.9025,0.095,0.0025
My desired output.file is:
0.1, 0.1, 0.1
Using an awk script called "parse.awk":
BEGIN {FS = ":"}
{for (i = 4; i <= NF; i += 2) printf ("%s%c", $i, i +2 <= NF ? "," : "\n ");}
which is invocated with:
awk -f parse.awk <input.file >output.file
my current output.file is as follows:
0.1,0.1,0.1
i.e. no spaces.
Changing pasre.awk to:
BEGIN {FS = ":"}
{for (i = 4; i <= NF; i += 2) printf ("%s%c", $i, i +2 <= NF ? ", " : "\n ");}
did not change the output.file. What change(s) to parse.awk will yield the desired output.file?
You may use this awk:
awk -F: -v OFS=', ' '{
for (i = 4; i <= NF; i += 2) printf "%s%s", $i, (i < NF-1 ? OFS : ORS)}' file
0.1, 0.1, 0.1
Could you please try following. Written and tested it in
https://ideone.com/e26q7u
awk '
BEGIN {FS = ":"}
val!=""{ print val; val=""}
{for (i = 4; i <= NF; i += 2){
val=(val==""?"":val", ")$i
}
}
END{
if(val!=""){
print val
}
}
' Input_file
The problem is when you changed the output separator from a single comma (",") to comma with space (", "); you did not change the format string from %c to %s. So that is how to fix your script:
BEGIN {FS = ":"}
{for (i = 4; i <= NF; i += 2) printf ("%s%s", $i, i +2 <= NF ? ", " : "\n ");}
# ^ Change this
I'm trying to parse Lua 5.3 strings. However, I encountered an issue. For example,
$ lua
Lua 5.3.4 Copyright (C) 1994-2017 Lua.org, PUC-Rio
> print(load('return "\\z \n\r \n\r \r\n \n \n \\x"', "#test"))
nil test:6: hexadecimal digit expected near '"\x"'
>
> print(load('return "\\z\n\r\n\r\r\n\n\n\\x"', "#test"))
nil test:6: hexadecimal digit expected near '"\x"'
Both of these error on line 6, and the logic behind that is pretty simple: eat newline characters (\r or \n) if they're different from the current one (I believe this to be an accurate description of how the lua lexer works, but I may be wrong).
I have this code, which should do it:
local ln = 1
local skip = false
local mode = 0
local prev
for at, crlf in eaten:gmatch('()[\r\n]') do
local last = eaten:sub(at-1, at-1)
if skip and prev == last and last ~= crlf then
skip = false
else
skip = true
ln = ln + 1
end
prev = crlf
end
It decides whether to eat newlines based on the previous char. Now, from what I can tell, this should work, but no matter what I do it doesn't seem to work. Other attempts have made it report 5 lines, while this one makes it report 9(!). What am I missing here? I'm running this on Lua 5.2.4.
This is part of a routine for parsing \z:
local function parse52(s)
local startChar = string.sub(s,1,1)
if startChar~="'" and startChar~='"' then
error("not a string", 0)
end
local c = 0
local ln = 1
local t = {}
local nj = 1
local eos = #s
local pat = "^(.-)([\\" .. startChar .. "\r\n])"
local mkerr = function(emsg, ...)
error(string.format('[%s]:%d: ' .. emsg, s, ln, ...), 0)
end
local lnj
repeat
lnj = nj
local i, j, part, k = string.find(s, pat, nj + 1, false)
if i then
c = c + 1
t[c] = part
if simpleEscapes[v] then
--[[ some code, some elseifs, some more code ]]
elseif v == "z" then
local eaten, np = s:match("^([\t\n\v\f\r ]*)%f[^\t\n\v\f\r ]()", nj+1)
local p=np
nj = p-1
--[[ the newline counting routine above ]]
--[[ some other elseifs ]]
end
else
nj = nil
end
until not nj
if s:sub(-1, -1) ~= startChar then
mkerr("unfinished string near <eof>")
end
return table.concat(t)
end
Compact code for iterating lines of Lua script:
local text = "First\n\r\n\r\r\n\n\nSixth"
local ln = 1
for line, newline in text:gmatch"([^\r\n]*)([\r\n]*)" do
print(ln, line)
ln = ln + #newline:gsub("\n+", "\0%0\0"):gsub(".%z.", "."):gsub("%z", "")
end
Efficient code for iterating lines of Lua script:
local text = "First\n\r\n\r\r\n\n\nSixth"
local sub = string.sub
local ln = 1
for line, newline in text:gmatch'([^\r\n]*)([\r\n]*)' do
print(ln, line)
local pos, max_pos = 1, #newline
while pos <= max_pos do
local crlf = sub(newline, pos, pos + 1)
if crlf == "\r\n" or crlf == "\n\r" then
pos = pos + 2
else
pos = pos + 1
end
ln = ln + 1
end
end