CLEO Help How do I compare two strings easily to see if they're equal?

CLEO related
Status
Not open for further replies.

Supermacy31

Active member
Joined
Mar 13, 2013
Messages
173
Reaction score
0
This snippet is in a label:

Code:
if 
0@ == 99 //Activated? Then execute function!
then
0AC8: 1@ = allocate_memory_size 260
0AF4: 1@ = read_string_from_ini_file "cleo\kbult.ini" section "connectmgr" key "state"
0AF9: samp say_msg 1@
if
1@ == '/connect' //Note that I tried " and it led to the same result.
then
0AF5: write_string "/disconnect" to_ini_file "cleo\kbult.ini" section "connectmgr" key "state"
else
0AF5: write_string "/connect" to_ini_file "cleo\kbult.ini" section "connectmgr" key "state"
end
0AC9: free_allocated_memory 1@ //Free!
0AF0: 1@ = get_int_from_ini_file "cleo\kbult.ini" section "kb" key "unislimit"
wait 1@
end

.INI:

Code:
[connectmgr]
state=/connect
This crashes the game when executed somehow/or it doesn't even let Sannybuilder compile it:
Code:
if
1@ == '/connect' //Note that I tried " and it led to the same result.
then
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
if 0C14: strcmp string1 0@ string2 1@ //case sensitive

if 0C21: stricmp string1 0@ string2 1@ //case insensitive
 

Supermacy31

Active member
Joined
Mar 13, 2013
Messages
173
Reaction score
0
monday said:
if 0C14: strcmp string1 0@ string2 1@ //case sensitive

if 0C21: stricmp string1 0@ string2 1@ //case insensitive
I need help in an issue that I'm having. CLEO is being retarded w/the variables:

if 
0@ == 99 //Activation
then
0AC8: 1@ = allocate_memory_size 260
0AF4: 1@ = read_string_from_ini_file "cleo\kbult.ini" section "ivswitches" key "s0"
0AF9: samp say_msg 1@
2@v = "hi"
4@v = "bye"
if 
0C14: strcmp string1 1@ string2 2@v // Case sensitive.
then
0AF5: write_string 4@v to_ini_file "cleo\kbult.ini" section "ivswitches" key "s0"
0AF9: samp say_msg 4@v
else
0AF5: write_string 2@v to_ini_file "cleo\kbult.ini" section "ivswitches" key "s0"
0AF9: samp say_msg 2@v
end
0AC9: free_allocated_memory 1@ //Free!
0AF0: 1@ = get_int_from_ini_file "cleo\kbult.ini" section "kb" key "unislimit"
wait 1@
end

Here is the .ini:

Code:
[ivswitches]
s0=hi

This is what to the output in chat is when I press the activation key:
I say: hi
I say: 

It's BLANK. The variable(s) are blank. But I clearly wrote strings into them. Why's that?

My SannyBuilder's settings are AS-IS.
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
idk why it doesn't write them but you could use opcodes instead of "2@v = 'hi' " and check if it works like:
06D2: 5@v = ""
or
0AD3: 5@v = format "" //probably works without params but I'm not sure

When you use @v keep in mind this:

springfield wrote:

0@s mean short string, you use it to store short strings(under 8bytes). It will also occupy the next variable.


0@ = 4 bytes
1@s = 8 bytes = 1@, 2@
1@v = 16 bytes = 1@, 2@, 3@, 4@
So using 2@v and 4@v could interfere with each other, I never tested it but I trust the above quote. I would rather use 2@v and 6@v instead
 

Supermacy31

Active member
Joined
Mar 13, 2013
Messages
173
Reaction score
0
monday said:
idk why it doesn't write them but you could use opcodes instead of "2@v = 'hi' " and check if it works like:
06D2: 5@v = ""
or
0AD3: 5@v = format "" //probably works without params but I'm not sure

When you use @v keep in mind this:

springfield wrote:

0@s mean short string, you use it to store short strings(under 8bytes). It will also occupy the next variable.


0@ = 4 bytes
1@s = 8 bytes = 1@, 2@
1@v = 16 bytes = 1@, 2@, 3@, 4@
So using 2@v and 4@v could interfere with each other, I never tested it but I trust the above quote. I would rather use 2@v and 6@v instead
For some shit reason, they don't work at all. Ugh.

Here's my current fix:

Code:
if 
0@ == 99 //Activation
then
0AC8: 1@ = allocate_memory_size 260
0AF4: 1@ = read_string_from_ini_file "cleo\kbult.ini" section "ivswitches" key "s0"
0AF9: samp say_msg 1@
if 
0C14: strcmp string1 1@ string2 2@v // Case sensitive.
then
06D2: 5@v = format "hi2"
0AF9: samp say_msg 5@v
else
06D2: 9@v = format "bye"
0AF9: samp say_msg 9@v
end
0AC9: free_allocated_memory 1@ //Free!
0AF0: 1@ = get_int_from_ini_file "cleo\kbult.ini" section "kb" key "unislimit"
wait 1@
end

Output in CHAT:

PHP:
I say: hi
I say:

That's once I activate the button. Why the fuck is this happening? The variable isn't recording shit, I also tried with just 5@v = "hi2" and etc. and it still won't record the fucking variable. What gives?
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
I haven't used cleo in a while, so i can't say 100% sure, but i remember SF didn't played well with @v strings.
So try using SF opcodes (say, strcmp etc.) only with local vars 0@-31@ and w/ 0A8C/0AC9.
 

Supermacy31

Active member
Joined
Mar 13, 2013
Messages
173
Reaction score
0
springfield said:
I haven't used cleo in a while, so i can't say 100% sure, but i remember SF didn't played well with @v strings.
So try using SF opcodes (say, strcmp etc.) only with local vars 0@-31@ and w/ 0A8C/0AC9.
OK I have tried to use it w/local vars. 0@-31@ however Sannybuilder doesn't let you compile if you assign them to strings, so like if I do 0@ = "Hi!" then Sannybuilder would not allow it.

I also don't know how to use : 0A8C so I can't comment on that.

Do you know of an easy way or a way for me?

I tried a lot of things. Can you show me?
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
My bad, i meant 0AC8/0AC9, the opcode to allocate/free memory. From your example i guess you know how to use them.

[shcode=cpp]
alloc 0@ = 128
    alloc 1@ = 32
    
    0AD3: 0@ = "Hello nr.%d" 51 //format string
    0C13: strcpy 1@ -> "hello"  //copy string
    
    if or 
        0C29: $1 = stristr string1 0@ string2 1@  //case sensitive
        0C18: $1 = strstr  string1 0@ string2 1@  
    then
        chatmsg "%s contains %s" -1 0@ 1@
    end
    
    free 0@
    free 1@
[/shcode]
 

Supermacy31

Active member
Joined
Mar 13, 2013
Messages
173
Reaction score
0
springfield said:
My bad, i meant 0AC8/0AC9, the opcode to allocate/free memory. From your example i guess you know how to use them.

[shcode=cpp]
   alloc 0@ = 128
    alloc 1@ = 32
    
    0AD3: 0@ = "Hello nr.%d" 51 //format string
    0C13: strcpy 1@ -> "hello"  //copy string
    
    if or 
        0C29: $1 = stristr string1 0@ string2 1@  //case sensitive
        0C18: $1 = strstr  string1 0@ string2 1@  
    then
        chatmsg "%s contains %s" -1 0@ 1@
    end
    
    free 0@
    free 1@
[/shcode]
Works!

Oh my!

It works, hurray!

Hip hip hurray!

I used this snippet:

Code:
0AC8: 2@ = allocate_memory_size 128
0AD3: 2@ = "Testing, testing, one-two-three." //Format string.
0AF9: samp say_msg 2@
0AC9: free_allocated_memory 2@ //Free!

Now the variable really records the strings and I can do things with it.

Once again, thank you. A lot!
 
Status
Not open for further replies.
Top