Using a Lua Script to send inputs to BizHawk - lua

I've tried using joypad.set(Inputs), but that doesn't seem to do anything. Also joypad.write(Inputs) doesn't even work. I'm stuck in a corner, and I don't know what to do.

This example works for when emulating a GBA. It will make the emulator press right every frame
input = {}
input['A'] = false
input['B'] = false
input['Down'] = false
input['L'] = false
input['Left'] = false
input['Power'] = false
input['R'] = false
input['Right'] = true
input['Select'] = false
input['Start'] = false
input['Up'] = false
while true do
joypad.set(input)
emu.frameadvance()
end
depending what you emulating this also might be useful
input['P1 A'] = false

Related

How do I stop indentation for braces in NeoVim (lua)

I am extremely new to Neovim and I am close to being done with configuring, but I can not seem to figure out how to fix braces indentation.
Here's the issue
What I want
function() {
print('Hello, world!')
}
What happens
function() {
print('Hello, world!')
}
Here is my settings.lua file
local set = vim.opt
set.expandtab = true
set.smarttab = true
set.shiftwidth = 4
set.tabstop = 4
set.hlsearch = true
set.incsearch = true
set.ignorecase = true
set.smartcase = true
set.splitbelow = true
set.splitright = true
set.wrap = true
set.scrolloff = 5
set.fileencoding = 'utf-8'
set.termguicolors = true
set.relativenumber = true
set.cursorline = true
set.hidden = true
Incase you're wondering, I'm using 'windwp/nvim-autopairs' to autopair the braces, brackets, etc. if that has anything to do with it.

Proximity prompt issue

basically after my math.random it will teleport you to a location and then after 20 seconds it will teleport you back. The proximity prompt that this script is in only fires this script once, i click the button to go to sleep and it does nothing, no error code no thing. On the other hand after the else statement i can click the button three separate times and then if i try clicking it a fourth time it no longer works, still with no error.
Is there anyway I can fix this?
Heres my code if helpful
game.Players.PlayerAdded:Connect(function(player)
script.Parent.Triggered:Connect(function(activated)
if activated then
print("activated")
if game.ReplicatedFirst.night.Value == true then
script.Parent.Enabled = false
local number = math.random(1, 2)
print(number)
if number == 1 then
local plr = game.Workspace:FindFirstChild(player.Name)
game.ReplicatedFirst.slep.Value = true
plr.Humanoid.HipHeight = -0.913
plr.HumanoidRootPart.Position = Vector3.new(327.227, 1.5, -348.899) + Vector3.new(0,10,0)
print("ho")
player.PlayerGui.slepgui.Enabled = false
wait(20)
game.Workspace:FindFirstChild(player.Name).HumanoidRootPart.Position = Vector3.new(31.546, 20.793, 12.62) + Vector3.new(0,10,0)
script.Parent.Enabled = true
game.ReplicatedFirst.night.Value = false
game.ReplicatedFirst.slep.Value = false
game.Workspace["Hotel - undertale"].Playing = true
game.Lighting.TimeOfDay = 12
else
local plr = game.Workspace:FindFirstChild(player.Name)
player.PlayerGui.slepgui.Enabled = true
script.Parent.Enabled = false
game.ReplicatedFirst.slep.Value = true
script.Parent.ObjectText = "Go to bed, this will skip the night"
game.Workspace["SNORING - SOUND EFFECT (128 kbps)"].Playing = true
print("number one worked")
wait(12)
plr.HumanoidRootPart.Position = Vector3.new(31.546, 20.793, 12.62) + Vector3.new(0,10,0)
game.ReplicatedFirst.night.Value = false
game.ReplicatedFirst.slep.Value = false
game.Workspace["Hotel - undertale"].Playing = true
player.PlayerGui.slepgui.Enabled = false
script.Parent.Enabled = true
game.Lighting.TimeOfDay = 12
script.Parent.ObjectText = "Go to bed. Only avaliable at night"
print("Numver two worked")
end
end
end
end)
end)
-- 327.227, 1.5, -348.899

Control line breaks in F# code formatted by Fantomas

I would like more control and customisation regarding where Fantomas inserts or remove a line break in the code that's formatted by Fantomas. For instance, the following function is formatted in one line but I would prefer having a line break.
module Xxx =
// Actual
let private emptyOrTrimmed (code: string) = if code = null then "" else code.Trim()
// Expected
let private emptyOrTrimmed (code: string) =
if code = null then "" else code.Trim()
How is it possible, preferably without touching the .editorconfig file (given below) ?
Can we add some comment in the code to disable one rule like it exists for eslint ?
// .editorconfig file
root = true
[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false
[*.fs]
end_of_line = lf
max_line_length = 210
fsharp_semicolon_at_end_of_line = false
fsharp_space_before_parameter = true
fsharp_space_before_lowercase_invocation = true
fsharp_space_before_uppercase_invocation = false
fsharp_space_before_class_constructor = false
fsharp_space_before_member = false
fsharp_space_before_colon = false
fsharp_space_after_comma = true
fsharp_space_before_semicolon = false
fsharp_space_after_semicolon = true
fsharp_indent_on_try_with = false
fsharp_space_around_delimiter = true
fsharp_max_if_then_else_short_width = 40
fsharp_max_infix_operator_expression = 50
fsharp_max_newline_infix_operator_expression_number_of_items = 1
fsharp_multiline_infix_multiline_formatter = character_width
fsharp_max_record_width = 40
fsharp_max_record_number_of_items = 1
fsharp_record_multiline_formatter = character_width
fsharp_max_array_or_list_width = 40
fsharp_max_array_or_list_number_of_items = 1
fsharp_array_or_list_multiline_formatter = character_width
fsharp_max_value_binding_width = 40
fsharp_max_function_binding_width = 40
fsharp_max_dot_get_expression_width = 50
fsharp_multiline_block_brackets_on_same_column = false
fsharp_newline_between_type_definition_and_members = false
fsharp_keep_if_then_in_same_line = true
fsharp_max_elmish_width = 10
fsharp_single_argument_web_mode = false
fsharp_align_function_signature_to_indentation = false
fsharp_alternative_long_member_definitions = true
fsharp_disable_elmish_syntax = false
fsharp_strict_mode = false
Just change this setting to assign it to zero:
fsharp_max_function_binding_width=0
Currently, I've managed to "force a line break" where I want, just by putting a comment in the code. In order to be explicit, the comment is // force-line-break, which looks like a "configuration comment" (e.g. for ESLint) but the comment can be anything.
But I still have no way to do the opposite: forcing no line break, which is occurring very often with record object.
Note: for me the most annoying thing with this code formatting is to have several blocks of code doing something similar but not formatted the same way regarding line breaks, which is breaking the symmetry and is penalizing the code scanning (meaning fast reading, where visual similarities help).

Why does my debounce not work, yet produce no errors?

Why does my debounce not work, yet produce no errors?
Here's my script so far, but it isn't working.
local UIS = game:GetService("UserInputService")
local toggle = false
script.Parent.BackpackFrame.Visible = false
script.Parent.BackpackText.Visible = false
UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
if toggle == false then
script.Parent.BackpackFrame.Visible = true
script.Parent.BackpackText.Visible = true
toggle = true
end
if toggle == true then
script.Parent.BackpackFrame.Visible = false
script.Parent.BackpackText.Visible = false
toggle = false
end
end
end)
If toggle is false you set it to true
if toggle == false then
script.Parent.BackpackFrame.Visible = true
script.Parent.BackpackText.Visible = true
toggle = true
end
And then immediately set it to false as you run into your second conditional statement.
if toggle == true then
script.Parent.BackpackFrame.Visible = false
script.Parent.BackpackText.Visible = false
toggle = false
end
So your change is revoked immediately befor anything had a chance to update.
If you have two exclusive states use if / else.
if toggle == false then
script.Parent.BackpackFrame.Visible = true
script.Parent.BackpackText.Visible = true
toggle = true
else
script.Parent.BackpackFrame.Visible = false
script.Parent.BackpackText.Visible = false
toggle = false
end
As all you're doing is to assign boolean values you can simply get rid of your conditions and do this:
toggle = not toggle -- toggle your state
-- assign the state to the visible property
script.Parent.BackpackFrame.Visible = toggle
script.Parent.BackpackText.Visibile = toggle
The code is setting toggle to false immediately after setting it to true.
if toggle == false then
-- false part
toggle = true
end
if toggle == true then
-- true part
toggle = false
end
Just use an else instead of checking toggle twice
if toggle then
-- true part
toggle = false
else
-- false part
toggle = true
end

Why when the components of this script, do they run fine but do not work when pieced together? There may just be a problem with it all together

This script is from Roblox Studio and is in Lua. I have tried using separate scripts but when I do, they don't work because of the bool value. The scripts seem either not to respond to it or it just doesn't update correctly. I have attached the picture of the hierarchy from ROBLOX Studio. I am reasonably to new to Lua but I am familiar with the basic concepts. I also know the Roblox Studio Interface deeply. If anyone could help, that would be greatly appreciated. Thanks in advance.
local lockvalue = script.Parent.Lockdown.Value
lockvalue = false
local RobBank = script.Parent["Rob Bank"]
local ClickDetector = RobBank:WaitForChild("ClickDetector")
local BillboardCXZ = RobBank:WaitForChild("BillboardGui")
local Billboard = BillboardCXZ:WaitForChild("TextLabel")
local emergencylight1 = script.Parent.Parent.EmergencyLight.Toggle.Value
local emergencylight2 = script.Parent.Parent.EmergencyLight2.Toggle.Value
local emergencylight3 = script.Parent.Parent.EmergencyLight3.Toggle.Value
local alarm1 = script.Parent.Parent.Alarm1.AlarmSound
local alarm2 = script.Parent.ParentAlarm2.AlarmSound
local Notif1 = script.Parent.NotifcationScreen.SurfaceGui.Frame.Visible
local Notif2 = script.Parent.NotifcationScreen.SurfaceGui.Frame.TextButton.MouseButton1Click
print ("Values Loaded.")
local function lock()
print ("LOCK FUNCTION ACTIVATED")
emergencylight1 = true
emergencylight2 = true
emergencylight3 = true
alarm1:play()
alarm2:play()
lockvalue = true
Notif1 = true
end
local function unlock()
print ("UNLOCK FUNCTION ACTIVATED")
emergencylight1 = false
emergencylight2 = false
emergencylight3 = false
alarm1.stop()
alarm2:stop()
lockvalue = false
Notif1 = false
end
Notif2:Connect(function()
unlock()
print ("Unlocked Via Override")
end)
RobBank.ClickDetector.MouseClick:Connect(function(Player)
print ("Functioning")
if Player and Player.Character then
print ("Milestone 2")
if lockvalue == false then
print ("After Lock Value")
if Player.Team == game.Teams.Criminal then
print ("Team Check")
local clicks = Player:FindFirstChild("leaderstats")["Bounty"]
clicks.Value = clicks.Value + 500
local clicks2 = Player:FindFirstChild("leaderstats")["Cash"]
clicks2.Value = clicks2.Value + 2500
Billboard.TextColor3 = Color3.new(1,0,0)
lock()
wait(60)
unlock()
Billboard.TextColor3 = Color3.new(0,1,0)
else
print("Player Is not On Crim team.")
Billboard.Text = ("You are on the Wrong Team!")
wait(3)
Billboard.Text = ("Steal Cash")
end
else
Billboard.Text = ("Already been recently robbed!")
wait(3)
Billboard.Text = ("Steal Cash")
end
end
end)
In Lua, a variable can be a reference to a table which has children (key/value pairs):
local myTable = { }
myTable.myKey = true
However, if you refer to a single child (by its key) then it will evaluate and pass only the resulting value into the variable (not a reference to the key itself).
local newVar = myTable.myKey
print(newVar) -- true
newVar = false
print(newVar) -- false
print(myTable.myKey) -- true, because we never changed myKey
So in the following statement, emergencylight1 is probably the value 'true' or 'false' rather than being a reference to the property itself.
local emergencylight1 = script.Parent.Parent.EmergencyLight.Toggle.Value
Recommendation
Ensure your variables are references to an actual table, and then refer to a child of that table (by its key) when assigning a new value.
local emergencylighttoggle1 = script.Parent.Parent.EmergencyLight.Toggle
local emergencylighttoggle2 = script.Parent.Parent.EmergencyLight2.Toggle
local emergencylighttoggle3 = script.Parent.Parent.EmergencyLight3.Toggle
local function lock()
emergencylighttoggle1.Value = true
emergencylighttoggle2.Value = true
emergencylighttoggle3.Value = true
end
local function unlock()
emergencylighttoggle1.Value = false
emergencylighttoggle2.Value = false
emergencylighttoggle3.Value = false
end

Resources