I'm trying to use the set_var command to change the value of the frame coordinates written to the system variable, but nothing works. How to write the code correctly??
How to change the values of a system variable via Karel??
-
A_ghost -
May 17, 2023 at 2:33 PM -
Thread is Unresolved
-
-
Hi A_ghost,
SET_VAR is the correct routine.
- Figure out the correct sysvar name e.g. '$XY_VAR[2].$A_Value'
- set prog_name to '*SYSTEM*'
- use the status var (with POST_ERR) to debug your code and get more information about your error(s)
- check the information the compiler/translater gives you
Best regards
-
The system variable "$EADER_FRM " you are are using doesn't seem to be a standard system variable, could you show the path you are taking to get to your screen?
Below is an example of how you can use the SET_VAR instruction in a Karel Routine (note: the parameter name might not be correct):
PROGRAM VAR_SET
--Translation Directive to work with system variables
%ENVIRONMENT sysdef
--Variable Definitions
VAR
status: INTEGER
tempInteger:INTEGER
parameter: STRING[40]
value: REAL
--Program Logic
BEGIN
parameter = '$EADER_FRM[1].$X'
value = 563.000
SET_VAR(tempInteger, '*SYSTEM*',parameter, value,status)
END VAR_SET
-
The system variable "$EADER_FRM " you are are using doesn't seem to be a standard system variable, could you show the path you are taking to get to your screen?
Below is an example of how you can use the SET_VAR instruction in a Karel Routine (note: the parameter name might not be correct):
PROGRAM VAR_SET
--Translation Directive to work with system variables
%ENVIRONMENT sysdef
--Variable Definitions
VAR
status: INTEGER
tempInteger:INTEGER
parameter: STRING[40]
value: REAL
--Program Logic
BEGIN
parameter = '$EADER_FRM[1].$X'
value = 563.000
SET_VAR(tempInteger, '*SYSTEM*',parameter, value,status)
END VAR_SET
I wrote the code, but when executing, the value of X does not change (((
-
Is the system variable locked??
-
Hi
as I wrote in my first answer:
Quote- use the status var (with POST_ERR) to debug your code and get more
information about your error(s)
e.g.
SET_VAR(.....,status)
IF status <> 0 THEN POST_ERR(status, '', 0, 2) ENDIF
And, are you sure you have to set these vars via karel?
I think it might be dangerous to edit the COORD-Frames directly, unless you really know what you're doing...
best regards
-
Hi
as I wrote in my first answer:
e.g.
SET_VAR(.....,status)
IF status <> 0 THEN POST_ERR(status, '', 0, 2) ENDIF
And, are you sure you have to set these vars via karel?
I think it might be dangerous to edit the COORD-Frames directly, unless you really know what you're doing...
best regard
When executing the program, it writes an unknown variable name. Why??
-
Hello A_ghost,
I have similar problem with another sys var
ThreadKarel set_var problem
niram83August 9, 2023 at 10:34 AM B.R.
-
Hi guys, I want to change the name of a variable ($pro_cfg.$prog_name) but in Karel it doesn't let me and I can't do it from the TP either. I wanted to make it equal to an SR (string Register). Any idea on how to change the name?
-
-
-
@ssaul what is "$pro_cfg.$prog_name" used for?
what error code do you get?
The variable $pro_cfg.$prog_name saves the name of the program that will be analyzed in Motion Profiler. I want to automate it to change the name of the program without having to go to the teach pendant.
-
Hi ssaul,
have you tried with SET_VAR builtin? Please try.
Info: Not all sysvars are directly supported within RG (maybe you have to set an(other) %environment), if not familiar with that, use SET_VAR.
-
Hi ssaul,
have you tried with SET_VAR builtin? Please try.
Info: Not all sysvars are directly supported within RG (maybe you have to set an(other) %environment), if not familiar with that, use SET_VAR.
hi PnsStarer
Currently this is my program, but I think the variable is not available for karel
PROGRAM set_prog_name
VAR
prog_name : STRING[32] -- Variable para almacenar el nombre del programa
status : INTEGER -- Variable para almacenar el estado de la operación
BEGIN
-- Inicializar la variable de estado
status = 0-- Leer el valor de SR[1] y almacenarlo en prog_name
GET_STR_REG(1, prog_name, status)-- Verificar si la operación de lectura fue exitosa
IF status = 0 THEN
-- Asignar el valor de prog_name a $PRO_CFG.$PROG_NAME
$PRO_CFG.$PROG_NAME = prog_name
-- Mostrar un mensaje de confirmación
WRITE('El nombre del programa ha sido establecido a: ', prog_name, CR)
ELSE
-- Mostrar un mensaje de error
WRITE('Error al leer el registro de cadena SR[1]', CR)
ENDIF
END set_prog_name -
Code
-- Asignar el valor de prog_name a $PRO_CFG.$PROG_NAME SET_VAR(ENTRY, '*SYSTEM*', '$PRO_CFG.$PROG_NAME', prog_name, STATUS) IF STATUS <> 0 THEN;POST_ERR(STATUS, '', 0, 2);ENDIF
you have also to add "ENTRY : integer" to var section...
please get familiar with the (common) builtins..
I haven't tested and I won't give you FULL program.... learning while coding
-
Code
-- Asignar el valor de prog_name a $PRO_CFG.$PROG_NAME SET_VAR(ENTRY, '*SYSTEM', '$PRO_CFG.$PROG_NAME', prog_name, STATUS) IF STATUS <> 0 THEN;POST_ERR(STATUS, '', 0, 2);ENDIF
you have also to add "ENTRY : integer" to var section...
please get familiar with the (common) builtins..
I haven't tested and I won't give you FULL program.... learning while coding
I don't want you to write the code, I just need to know if you can use the variable in Karel because I think it's protected.
-
Hi ssaul
now I'm confused!
I just need to know if you can use the variable in Karel because I think it's protected.
What do you mean? It's writeable.
But I do not know if it's is 'allowed' to change this 'manually' since this var is part of a struct so maybe you'll get unwanted behavior..
-
Hi ssaul
now I'm confused!
What do you mean? It's writeable.
But I do not know if it's is 'allowed' to change this 'manually' since this var is part of a struct so maybe you'll get unwanted behavior..
Hello, good morning. It won't let me write it, hahaha. I write it, and the variable doesn't change color to indicate that it's being viewed. Sorry for my English. I use a translator.