Jump to content

cleo script to look for .ini file and generate one if not exists ?


SideLo

Recommended Posts

Hello, I am beginner to cleo scripts, I used chatgpt to help me code but couldn't get it to work.

 

What I am trying to do is script should look if SFSIHelper.ini exists or not, If not it should generate it and write:

"[Select]

Language=1"

in it

 

 

{$CLEO .cs}
thread 'INI'
var
    @iniFile: string

const
    INI_FILE = "SFSIHelper.ini"

begin
    @iniFile = INI_FILE

    if not FileExists(@iniFile) then
        WritePrivateProfileString("[Select]", "Language", "1", @iniFile)
    end

end

 

Another method I tried from a different script

 

{$CLEO}
0000:

repeat
wait 0
until 0afa: 

chatmsg "test mod loaded" 0x3399ff
   
WHILE TRUE
wait 0

IF
8AAB: file_exists "CLEO\SFSIHelper.ini"
THEN
    WHILE 8A9A: 20@ = openfile "CLEO\SFSIHelper.ini" mode "at"
    wait 0
    END
    0AD9: write_text "[Select]%c" in_file 20@ 0xA
    0AD9: write_text "Language=1" in_file 20@ 0xA
    0A9B: closefile 20@
END
wait 500
END 

 

Both methods are not working for me

Link to comment
Share on other sites

{$CLEO .cs}
script_name 'Test'

:Start
wait 0

if
0AAB:   does_file_exist "cleo\SFSIHelper.ini"
jf @create_file //jump-if-false - if no file, then jump to create_file
jump @end //jump to end of script (or change it to your code)   

:create_file
0A9A: 1@ = open_file "cleo\SFSIHelper.ini" mode "at+" //file will be created in CLEO folder
0AD9: write_formatted_text "[Select]%c" in_file 1@ 0xA
0AD9: write_formatted_text "Language=1" in_file 1@

:end
0A93: terminate_this_custom_script

I don't think that using ChatGPT will help. In my opinion it would just lead to more confusion. Read some existing scripts, notice how they start and how they end. Try the usual 'Hello, world !" stuff.

Edited by vladvo
Link to comment
Share on other sites

You can use CLEO's ini files dedicated opcodes:
 

if
    8AF0: not 0@ = read_int_from_ini_file "cleo\config.ini" section "SectionName" key "intKey"
then
    0AF1: write_int 77 to_ini_file "cleo\config.ini" section "SectionName" key "intKey"
end

 

Link to comment
Share on other sites

On 7/17/2023 at 2:02 AM, vladvo said:
{$CLEO .cs}
script_name 'Test'

:Start
wait 0

if
0AAB:   does_file_exist "cleo\SFSIHelper.ini"
jf @create_file //jump-if-false - if no file, then jump to create_file
jump @end //jump to end of script (or change it to your code)   

:create_file
0A9A: 1@ = open_file "cleo\SFSIHelper.ini" mode "at+" //file will be created in CLEO folder
0AD9: write_formatted_text "[Select]%c" in_file 1@ 0xA
0AD9: write_formatted_text "Language=1" in_file 1@

:end
0A93: terminate_this_custom_script

I don't think that using ChatGPT will help. In my opinion it would just lead to more confusion. Read some existing scripts, notice how they start and how they end. Try the usual 'Hello, world !" stuff.

 

I realized ChatGPT does not give accurate script so it's not gonna work.

I will try your example code and learn the mechanism of it, really thanks for your time and help you are amazing can you recommend me some guide(already following Cleo Script Tutorial by ZAZ) or video tutorial to learn scripting basics

 

12 hours ago, MiranDMC said:

You can use CLEO's ini files dedicated opcodes:
 

if
    8AF0: not 0@ = read_int_from_ini_file "cleo\config.ini" section "SectionName" key "intKey"
then
    0AF1: write_int 77 to_ini_file "cleo\config.ini" section "SectionName" key "intKey"
end

 

 

I appreciate for the help, I am still a beginner following this guide "Cleo Script Tutorial -by ZAZ", I got the point of the code i will try it

Edited by SideLo
Link to comment
Share on other sites

7 minutes ago, SideLo said:

can you recommend me some guide

Nope, don't know any other guides, except Sanny Builder's offline help. When I suddenly decided that I am interested in SA modding - I just tried a few easy scripts (like aforementioned 'Hello, World'). Then try the same 'Hello World' but make it more complex - like show text when CJ is in area (sphere) or by keypress. 
Browse opcodes at https://library.sannybuilder.com/#/sa/classes  Simply reading names of opcodes might give you an impression on what could be done with CLEO. Next. Think what you want your mod to do. Don't go for complex stuff. Make something easy but make it very stable. Learn conditions - you have to check various events and handle them at the right time, so your mod won't crash.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.