CLEO Help Multiple commands overwrite the data problem

CLEO related
Status
Not open for further replies.

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
I don't know what is the reason but it seems like some variables get overwritten somehow when I use more than one command.


According to the code below. When I type "/firstcommand AAAAAAAA" it displays the AAAAAAA(1@) in the chat. Then I type "/secondcommand BBBBBBBBB" and it displays BBBBBBBB in the chat as 1@ and as 2@. 1@ which was AAAAAA gets replaced somehow with the data from other command
Code:
0B34: samp register_client_command "firstcommand" to_label @Label1
0B34: samp register_client_command "secondcommand" to_label @Label2
31@ = 0

:First
wait 0
if 31@ == 1
then
0AF8: samp add_message_to_chat 1@ color 0xFF4800
end
if 31@ == 2
then
0AF8: samp add_message_to_chat 1@ color 0xFF4800
0AF8: samp add_message_to_chat 2@ color 0xFF4800




:Label1
wait 0
0B35: samp 1@ = get_last_command_params 
if 0AD4: 3@ = scan_string 1@ format "%s" 30@
then     
31@ = 1   
else  
31@ = 0
end
samp.CmdRet
jump @First


:Label2
wait 0
0B35: samp 2@ = get_last_command_params
if 0AD4: 3@ = scan_string 2@ format "%s" 31@
then
31@ = 2
else  
31@ = 0
end
samp.CmdRet
jump @First
 

T3KTONIT

Well-known member
Joined
Sep 2, 2013
Messages
308
Reaction score
5
i don't understand what's your problem...

but your code is correct and what it does it prints
0AF8: samp add_message_to_chat 1@ color 0xFF4800
0AF8: samp add_message_to_chat 2@ color 0xFF4800
when you use the second command
and it only prints
0AF8: samp add_message_to_chat 1@ color 0xFF4800
when you use the first command .... ? what else do u want??
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
What my code does is:
[member=5679]T3K[/member]
I type - /firstcommand AAAAAAAAA
The result: "AAAAAAA" is stored to 1@ and is displayed
Then I type - /secondcommand BBBBBBBBBB
The result: "BBBBBBB" is stored to 2@ and 1@ too

That's the problem, I'd like to have AAAAAAAA in 1@ and BBBBBBBB in 2@ but the code saves BBBBBBB to both variables 1@ and 2@. I don't know how and why but that's the result I get


[member=60]Opcode.eXe[/member]
I tried to adjust the variables so no single variable repeated but the result is still the same, 1@ and 2@ show the same thing.
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
I tried before but both strings were displayed like: "AAAAAA';';';'././.;l;l.."  "BBBBBBBBB;';';[;[;';" instead of "AAAAAAAA" "BBBBBBB".

Edit: My bad I tried it with the scan string opcode, not add_samp_to_chat, gonna try it now.
Edit 2: It displays "BBBBBBB  BBBBBBB"
 

pepeelpubero

Well-known member
Joined
Jan 21, 2014
Messages
433
Reaction score
1
How do you have the formats tab (case converting)? Be sure you got it to "AS IS". If all is ok wait for springfield he can help you.
 

T3KTONIT

Well-known member
Joined
Sep 2, 2013
Messages
308
Reaction score
5
monday link said:
What my code does is:
[member=5679]T3K[/member]
I type - /firstcommand AAAAAAAAA
The result: "AAAAAAA" is stored to 1@ and is displayed
Then I type - /secondcommand BBBBBBBBBB
The result: "BBBBBBB" is stored to 2@ and 1@ too

That's the problem, I'd like to have AAAAAAAA in 1@ and BBBBBBBB in 2@ but the code saves BBBBBBB to both variables 1@ and 2@. I don't know how and why but that's the result I get


[member=60]Opcode.eXe[/member]
I tried to adjust the variables so no single variable repeated but the result is still the same, 1@ and 2@ show the same thing.
in your code you have this :
if 31@ == 1
then
0AF8: samp add_message_to_chat 1@ color 0xFF4800
end
if 31@ == 2
then
0AF8: samp add_message_to_chat 1@ color 0xFF4800
0AF8: samp add_message_to_chat 2@ color 0xFF4800
Still i don't understand what else you want dude...
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
0AF8: samp add_message_to_chat 1@ color 0xFF4800
0AF8: samp add_message_to_chat 2@ color 0xFF4800
They show the same thing unfortunately

Edit: Maybe there's something wrong with my game? The exact code below tested by me shows the same value of 1@ 2@ when the second command is typed. If there's anyone who would test it on their PC it would be appreciated
Code:
{$CLEO .cs}
0000: NOP 

0B34: samp register_client_command "firstcommand" to_label @Label1
0B34: samp register_client_command "secondcommand" to_label @Label2
31@ = 0

:First
wait 0
if 31@ == 1
then
0AF8: samp add_message_to_chat 1@ color 0xFF4800
31@ = 0
end
if 31@ == 2
then
0AF8: samp add_message_to_chat 1@ color 0xFF4800
0AF8: samp add_message_to_chat 2@ color 0xFF4800
31@ = 0
end
jump @First



:Label1
wait 0
0B35: samp 1@ = get_last_command_params 
if 0AD4: 3@ = scan_string 1@ format "%s" 30@
then     
31@ = 1   
else  
31@ = 0
end
samp.CmdRet
jump @First


:Label2
wait 0
0B35: samp 2@ = get_last_command_params
if 0AD4: 4@ = scan_string 2@ format "%s" 29@
then
31@ = 2
else  
31@ = 0
end
samp.CmdRet
jump @First
 

T3KTONIT

Well-known member
Joined
Sep 2, 2013
Messages
308
Reaction score
5
monday link said:
0AF8: samp add_message_to_chat 1@ color 0xFF4800
0AF8: samp add_message_to_chat 2@ color 0xFF4800
They show the same thing unfortunately

Edit: Maybe there's something wrong with my game? The exact code below tested by me shows the same value of 1@ 2@ when the second command is typed. If there's anyone who would test it on their PC it would be appreciated
Code:
{$CLEO .cs}
0000: NOP 

0B34: samp register_client_command "firstcommand" to_label @Label1
0B34: samp register_client_command "secondcommand" to_label @Label2
31@ = 0

:First
wait 0
if 31@ == 1
then
0AF8: samp add_message_to_chat 1@ color 0xFF4800
31@ = 0
end
if 31@ == 2
then
0AF8: samp add_message_to_chat 1@ color 0xFF4800
0AF8: samp add_message_to_chat 2@ color 0xFF4800
31@ = 0
end
jump @First



:Label1
wait 0
0B35: samp 1@ = get_last_command_params 
if 0AD4: 3@ = scan_string 1@ format "%s" 30@
then     
31@ = 1   
else  
31@ = 0
end
samp.CmdRet
jump @First


:Label2
wait 0
0B35: samp 2@ = get_last_command_params
if 0AD4: 4@ = scan_string 2@ format "%s" 29@
then
31@ = 2
else  
31@ = 0
end
samp.CmdRet
jump @First

try maybe cleaning them?? like :

Code:
31@ = 0
1@ = 0
2@ = 0
 

Opcode.eXe

Expert
Joined
Feb 18, 2013
Messages
1,486
Reaction score
227
Location
( ͡° ͜ʖ ͡°)
INFO: I didn't read.

You said that 1@ is in 2@.

Its because 1@ can only store up like 6 letters. If its more than 6 letters its gonna grab the next variable and store the other parts in there. You have to allocate memory:
0AC8: 0@ = allocate_memory_size 260

Now you can store a long text in 0@
example: "LOOOOOOOOOOOOOOOOOOOL THIS IS SO LOOONNGG OMFG!!"

and when you dont need it anymore you just free the memory

0AC9: free_allocated_memory 0@
 

Opcode.eXe

Expert
Joined
Feb 18, 2013
Messages
1,486
Reaction score
227
Location
( ͡° ͜ʖ ͡°)
I also noticed that your code is completly wrong.

Why do you jump at :FIRST, when you dont need it? cmdret is gonna return to that line where it was the last time.
Code:
samp.CmdRet
jump @First
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
Sampfuncs allocates memory for 0B35 but after 0B43 free it.
So if you have multiple commands use only one variable for all 0B35.
Code:
0AC8: 1@ = 260  //alocate memory for the strings.
0AC8: 2@ = 260  //don't use 0AC8 in a loop w/o 0AC9.
0B34: samp register_client_command "firstcommand" to_label @Label1
0B34: samp register_client_command "secondcommand" to_label @Label2


while true
    wait 0
    if 31@ == 1
    then 
        0AF8: 1@ 0xFF4800
        31@ = 0
    else
        if 31@ == 2
        then 
            0AF8: 1@ 0xFF4800
            0AF8: 2@ 0xFF4800
            31@ = 0   
        end
    end
end

:label1
0B35: 0@
if 0ad4: $nouse = 0@ "%s" $nouse //pointless, since 0@ is a string already
then 31@ = 1
    0C13: strcpy destination 1@ source 0@ //copy string from 0@ to 1@
else 31@ = 0  
end
0B43: ret

:label2
0B35: 0@
if 0ad4: $nouse = 0@ "%s" $nouse 
then 31@ = 2
    0C13: strcpy destination 2@ source 0@
else 31@ = 0
end
0B43: 
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
[member=60]Opcode.eXe[/member]
Actually jump@First wasn't there but everytime something doesn't work in the code I'm getting paranoid and change everything i'm not 100% sure about;d

[member=111]springfield[/member]
Thank you, it works:)
 
Status
Not open for further replies.
Top