I modified the above code but it still doesn't work. Is it a bug in ROS?
No. The issue is the "1" in "/file get 1 content" (or, /file get "1" content, both same). What using a numeric (or string that is a number) in "get" does is tell it to get the file at index 1 from last /file/print. While using a filename in "/file get ..." works, not if the name is a numeric since that the primary logic in get.
I suspect being explicit like this would help:
:local q [/file get [find name=1.txt] contents]
{
:local yys 134 ;
:local gsd 1936 ;
:if ([:len [/file find name=("Save-".$yys.$gsd.".txt") ] ] > 0) do={
:global q [/file get ("Save-".$yys.$gsd.".txt") contents]
} else={
/file print file=("Save-".$yys.$gsd.".txt")
:delay 2
:global q 0
}
:log warning $q ;
}
Sorry~No help! What I said is that it is possible to assign values within IF, but not outside IF? I have now rewritten the script without using 1. txt, but I still cannot assign a value to variable q because there are two situations: 1) when there is no file, a new file will be created and q will be assigned a value of 0; 2) when there is a file, a number will be read from the file and assigned to variable q. This variable is intended to be used in a loop in the underlying code, such as for p from=$q to=99999 do={}. Isn't this considered a bug in ROS? Is there a problem with the writing style?