KRL: I want to use the Status Keys of the KRC4 Tablet to send outputs - krl

i already have my code and if i am wrong please correct me.
But the code isnt my problem ... i dont know where and how i use it in the KRC4 interface i thought a .src file would be enough inside of the KRC -> R1 -> System Folder ... but guess what it does not work like that.
I never had a programming course in KRL so i am missing a basic step to use my code.
CODE:
DEF StatusKey()
;FOLD +> Status Key detection
; check if status key is pressed
$FLAG[11]=is_key_pressed(14)
$FLAG[12]=is_key_pressed(15)
$FLAG[13]=is_key_pressed(16)
$FLAG[14]=is_key_pressed(17)
; detect rising edge of the button press
; by comparing current and remembered state
$FLAG[1] = $FLAG[11] AND NOT $FLAG[15]
$FLAG[2] = $FLAG[12] AND NOT $FLAG[16]
$FLAG[3] = $FLAG[13] AND NOT $FLAG[17]
$FLAG[4] = $FLAG[14] AND NOT $FLAG[18]
; remember previous state of the button
$FLAG[15]=$FLAG[11]
$FLAG[16]=$FLAG[12]
$FLAG[17]=$FLAG[13]
$FLAG[18]=$FLAG[14]
;ENDFOLD
;FOLD +> Status Key control
; allow status keys to control some outputs
; but only if in T1 and drives are enables
IF $T1 AND $PERI_RDY AND $USER_SAF AND NOT $PRO_ACT THEN
; for momentary state change (toggle) use flags 1..4
IF $FLAG[1] THEN
$OUT[1] = True
ENDIF
IF $FLAG[2] THEN
$OUT[1] = False
ENDIF
; for continuous outputs use flags 11..14
; $OUT[1] = $FLAG[11] ; already used for output 1
; $OUT[2] = $FLAG[12] ; already used for output 1
; $OUT[3] = $FLAG[13]
; $OUT[4] = $FLAG[14]
ENDIF
;ENDFOLD
END

You need to put this in a *.sub for it to evaluate cyclically. You can also just call statuskey() from a submit in case you do not want to move the code.
Keep in mind to never put waits or similar in sps.sub

Related

Roblox remoteevents change value

local script
function Click(player)
if game.Workspace.Folder.Value == 0 then local num = 1
elseif game.Workspace.Folder.Value == 1 then local num = 0
game.ReplicatedStorage.Test:FireServer(player ,num)
end
script.Parent.ClickDetector.MouseClick:connect(Click)
end
server script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.Test.OnServerEvent:Connect(function(player ,num)
if player:GetRankInGroup(1) > 248 then
game.Workspace.Folder.Value = num
else
end
end
)
Doesn't work at all, tried testing if it even connects by printing stuff.
You have a bunch of issues.
1. LocalScripts only run in a few locations, and the Workspace isn't one of them.
Based on your code, I'm assuming this LocalScript is a child of a ClickDetector in the Workspace.
See the docs for LocalScripts :
A LocalScript will only run Lua code if it is a descendant of one of the following objects:
A Player’s Backpack, such as a child of a Tool
A Player’s character model
A Player’s PlayerGui
A Player’s PlayerScripts.
The ReplicatedFirst service
So you need to move the LocalScript to a location where it will actually run, then update the path to the ClickDetector.
-- find the detector in the Workspace
local detector = game.Workspace.Part.ClickDetector
detector.MouseClick:Connect(Click)
2. The connection is inside a function that never gets called.
This looks like a typo, but the line where the MouseClick signal is connected to happens inside the Click function, not outside. So effectively, the Click function is declared and never called by anything. You need to move it outside the last end
3. Variables declared using `local` are only accessible at the level (or deeper) that they are declared at.
Let me annotate your code to highlight what's happening...
local function Click(player)
if game.Workspace.Folder.Value == 0 then
local num = 1
-- num stops existing here and Test is never fired
elseif game.Workspace.Folder.Value == 1 then
local num = 0
game.ReplicatedStorage.Test:FireServer(num)
-- Test is fired with a value of 0 only when Folder.Value equals 1
end
end
local detector = game.Workspace.Part.ClickDetector
detector.MouseClick:Connect(Click)
To fix this, you need to move the local num declaration to a higher scope so it is encapsulates the if-statement. Then you need to make sure that the Remote event is fired in both cases, so you should move it outside the if-statement...
function Click(player)
-- define num
local num
if game.Workspace.Folder.Value == 0 then
num = 1
else --if game.Workspace.Folder.Value == 1 then
num = 0
end
-- fire the RemoteEvent
game.ReplicatedStorage.Test:FireServer(num)
end
local detector = game.Workspace.Part.ClickDetector
detector.MouseClick:Connect(Click)
4. (Nit-pick) Bad tabbing in your server Script creates confusion
This is not something you need to fix, but as atomfrog pointed out, nothing is happening in your Script's else block. It is unnecessary to have it at all, and it looks like you tried to use end to escape from the Script, but all you've done is indented your if-statement incorrectly. If you want to escape or for nothing to happen, use return, or don't have an else block.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.Test.OnServerEvent:Connect( function(player, num)
local specialGroupId = 1
local lowestPermissionLevel = 248
if player:GetRankInGroup(specialGroupId) > lowestPermissionLevel then
game.Workspace.Folder.Value = num
end
end)
maybe it doesn't work because you have nothing after the else

Why is KbCheck in Psychtoolbox not registering keyboard input?

I'm trying to run a programme coded in Psychtoolbox-3 that should register a keypress. But when I run it, even just this section from the command window, it doesn't respond to the E, P keys (or any) and I have to stop the operation using Ctrl-C. I have tried changing it to {e, p} (which are the names I found using KbName('KeyNames')), but it doesn't work.
The same code works on my supervisor's computer - I am using a Mac with OS 11.1.
KbName('UnifyKeyNames');
keyresp = KbName({'E','P'});
key = 0;
while ~key
[key,tkey] = CheckKeyPress(keyresp);
end
The CheckKeyPress is this function (and it works - gives output 0):
function [key,tkey] = CheckKeyPress(whichkeys)
if nargin < 1 || isempty(whichkeys)
whichkeys = 1:256;
end
key = 0;
[iskeydown,tkey,keys] = KbCheck(-1);
if any(keys(whichkeys))
key = find(keys(whichkeys),1);
end
end
I have also tried looking at PsychHID('Devices') and my keyboard is there (and no other keyboards).
Thanks for any help!
Solved! It was a simple mac problem :)
After I tried KbQueueCreate and got an error message I found the same one on another thread - the only problem is I had to allow Matlab to access keyboard input on my laptop.
Settings - Security and Privacy - Input Monitoring
It is always a big pain in MacOs. I use this code:
close all
clear all
clc
ListenChar(0);
Devices=PsychHID('Devices');
keyboardsIDs = [];
for iiD = 1:numel(Devices)
try
KbQueueCreate(Devices(iiD).index);
KbQueueStart(Devices(iiD).index);
keyboardsIDs(end+1,1) = Devices(iiD).index;
end
end
stopScript = 0;
while ~stopScript
for iiD = 1:numel(keyboardsIDs)
[keyIsDown, firstPress]=KbQueueCheck(keyboardsIDs(iiD));
if keyIsDown
keyID = find(firstPress)
disp(keyID)
if any(keyID ==20), stopScript =1; end
end
end
end
for iiD = 1:numel(keyboardsIDs)
KbQueueStop(keyboardsIDs(iiD));
end
ListenChar();
UPDATE
This is a bit dirty workaround, but it will works in any situation.
Press 'q' to exit the loop

using REXX to access vm370 disks

REXX is completely new to me, I like it so far. I am using SixPack running on Hercules. VM/370 is a nice environment, but I am trying to make it user friendly; filling in scripts for everything that works-so as to not need to repeat my steps.
The file attached below was written to search in ISFP, instead I want it to access disks. It searches for a specified file.
I do not know enough to rewrite a REXX program. It stops at strange places saying "found" this or that. Please, give any suggestions.
/* REXX */
ARG PROGNAME
PROGNAME = STRIP(PROGNAME)
ACCESS_TEMPLATE='A2 Y U'
USE VAR ACCESS_TEMPLATE A2 Y U /* NOT PARSE */
VAR1 = A2
VAR2 = Y
VAR3 = U
IF PROGNAME == '' THEN DO
SAY 'ENTER MEMBER NAME'
FULL PROGNAME
PROGNAME = STRIP(PROGNAME)
IF PROGNAME == '' THEN DO
SAY NO MEMBER ENTERED. EXITING THE PROGRAM
EXIT
END
END
SEARCH.1 = PROD1.LIB
SEARCH.2 = PROD2.LIB
SEARCH.3 = PROD3.LIB
CNT = 3
FND = 'N'
DO I = 1 TO CNT
ACCESS 'VAR1' 'VAR2' 'VAR3'
LIB = LIST.I(PROGNAME)
IF SYSDSN('LIB') == OK THEN DO
FND = 'Y'
TYPE('LIB')
END
END
IF FND == 'N'THEN DO
SAY MEMBERS NOT FOUND IN ANY LIBRARIES
SAY PLEASE CHECK THE MEMBER ENTERED
EXIT
END
This is a bit late but it's good advice for novice REXX programmers...
Right near the top of your program put in this:
SIGNAL ON NOVALUE
and then near the every end...
NOVALUE: SAY 'NOVALUE error at line' SIGL
exit 4
Why? REXX has a "feature" in that every undefined variable resolves to its own name in UPPER case, like this:
myvar1='hi there'
mayvar2=', joe'
say myvar1||myvar2
What you probably intended to SAY was
'hi there, joe'
but instead got
'hi thereMYVAR2'
If you had SIGNAL ON NOVALUE it would have given you an error message which is a lot better. I ALWAYS put this into my code.

LibreOffice Macro always show #NULL! after reopening the file

I wrote a macro in LibreOffice Calc and it is able to run correctly. But if I close the file and reopen, it always show #NULL! instead of the correct value. What am I missing here?
My macro code
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Function Calculate(CalType As String) As Double
'
' Calculate Macro
'
Dim i As Integer
Calc = 0
i = 1
Do While Not IsEmpty(Cells(i, 2))
If (Cells(i, 3).Value = CalType And (Cells(i,2) = "A" Or Cells(i,2) = "B")) Then
Calculate = Calculate + Cells(i, 4).Value
ElseIf (Cells(i, 3).Value = CalType And Cells(i,2) = "C") Then
Calculate = Calculate - Cells(i, 4).Value
End If
i = i + 1
Loop
'
End Function
The calling function will be something like =Calculate(J6)
The file is saved as .ods format.
The Cells call did not work at all for me. It is from VBA, not LO Basic. However I do not think that is the main problem.
LibreOffice expects that user-defined functions will be simple, only accessing the cell that contains the formula. Since the spreadsheet has not been fully loaded yet when the function is called, it is not possible to read other cells.
The workaround is to ignore errors and wait until the document is fully loaded before running the function. Take the following code as an example:
Function ReadOtherCell(row, col)
On Error GoTo ErrorHandler
oSheet = ThisComponent.CurrentController.ActiveSheet()
oCell = oSheet.getCellByPosition(row, col)
ReadOtherCell = "value is '" & oCell.getString() & "'"
Exit Function
ErrorHandler:
Reset
End Function
Sub RecalculateAll
' This is for user-defined functions that need to read the spreadsheet.
' Assign it to the "View created" event,
' because before that, the spreadsheet is not fully loaded.
ThisComponent.calculateAll
End Sub
Enter foo in A1, and =ReadOtherCell(0,0) in A2. So far, this has the same problem -- It will fail when the document is first opened.
Now, go to Tools -> Customize. In the Events tab, highlight View created. Press Macro... and find the RecalculateAll function. Then press OK.
Now when the document is closed and reopened, cell A2 should show the result value is 'foo'.
This is derived from B. Marcelly's answer at http://ooo-forums.apache.org/en/forum/viewtopic.php?f=20&t=73090&sid=f92a89d676058ab597b4b4494833b2a0.
I had the same problem.
I noticed that in the module, i had an empty Sub Main
After i 've erased it, the functions started working again

Keeping information on Form B from Form A when Form A is closed

I was wondering if there is any code that lets some information you enter on Form A remain in the textboxes in Form B when Form A is closed. Im hoping to keep some user information entered into the first form on the second form and still have the first form close.
Thank you!
You can't maintain value from field when you close a form. So you can create some Global vars to copy his value and maintain on memory.
Sometimes i use another option: hide the form A meanwhile you use form B, then when you need to close Form B, simply check if A is open and then close it.
Function FIsLoaded(stFrmName$) As Integer
Dim I As Integer
For I% = 0 To Forms.Count - 1
If (Forms(I%).FormName = stFrmName$) Then
FIsLoaded = True
Exit Function
End If
Next I%
For I% = 0 To Reports.Count - 1
If (Reports(I%).FormName = stFrmName$) Then
FIsLoaded = True
Exit Function
End If
Next I%
FIsLoaded = False
End Function
With this function you can do before close form:
if fisloaded("formA") then
DoCmd.Close acForm ,"formA"
end if