Jump to content

Error when using "timera" in cleo script


Gdzin

Recommended Posts

In the label "1", in the condition that checks if the player pressed the widget 70, inside the while true, in the condition that checks if "$Index" is different from 2, when I call the function of the label "time" everything works right, but the second time I call this function, after the "return" function, the time is not counted correctly the same as the first time, like it enters the function and comes back at the same moment, and this is disturbing me because I need that time to not be detected on the samp server I play

 

______________________________________________________________

 

:1
wait 0

$Auto = false

if
    0A51: is_widget_pressed 8
then
    gosub @Teleport
    gosub @Not_Pressed
end

if
    0A51: is_widget_pressed 70
then
    gosub @Not_Pressed
    
    $Auto = true
    
    if and
        0811: $Car = actor $PLAYER_ACTOR used_car
        $Car >= 0 
    then
        0407: store_coords_to $PlayerX $PlayerY $PlayerZ from_car $Car with_offset 0.0 0.0 -1.0
    else
        04C4: store_coords_to $PlayerX $PlayerY $PlayerZ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 -1.0
    end
    
    0172: $Player_Angle = actor $PLAYER_ACTOR Z_angle
    
    
    while true
        
        wait 0
        
        gosub @Teleport
        
        if
            $Indice <> 2
        then
            gosub @Time
            gosub @Return
            gosub @Time
        end
        
        if
            0A51: is_widget_pressed 8
        then
        end
        
        if
            0A51: is_widget_pressed 70
        then
            gosub @Return
            gosub @Not_Pressed
            break
        end
        
        gosub @End
        
    end
    
end

gosub @End
goto @1


:Teleport
0DD8: $Detection[0] = read_mem_addr $Detection_Address[0] size 1 add_ib 0
0DD8: $Detection[1] = read_mem_addr $Detection_Address[1] size 1 add_ib 0

if
    $Detection[0] <> 0
then
    $Indice = 0
else if
    $Detection[1] <> 0
then
    $Indice = 1
else
    $Indice = 2
end
end

if
    $Indice <> 2
then
    0DD8: $CheckPointX = read_mem_addr $CheckPointX_Address($Indice,2i) size 4 add_ib 0
    0DD8: $CheckPointY = read_mem_addr $CheckPointY_Address($Indice,2i) size 4 add_ib 0
    0DD8: $CheckPointZ = read_mem_addr $CheckPointZ_Address($Indice,2i) size 4 add_ib 0
    
    if and
        $CheckPointX <> 0.0
        $CheckPointY <> 0.0
    then
        00A1: put_actor $PLAYER_ACTOR at $CheckPointX $CheckPointY $CheckPointZ
    else
        $Indice = 2
    end

end

return


:Return
00A1: put_actor $PLAYER_ACTOR at $PlayerX $PlayerY $PlayerZ
            
if and
    0811: $Car = actor $PLAYER_ACTOR used_car
    $Car >= 0 
then
    0175: set_car $Car Z_angle_to $Player_Angle 
else
    0173: set_actor $PLAYER_ACTOR Z_angle_to $Player_Angle
end

return


:Time
Timera = 0
while Timera < 1000             
    
    wait 0
    
    if
        0A51: is_widget_pressed 8
    then
    end
    
    if
        0A51: is_widget_pressed 70
    then
        gosub @Return
        gosub @Not_Pressed
        goto @1
    end
    
    gosub @End
                           
end
return


:Not_Pressed
wait 0
if and
8A51: not is_widget_pressed 8
8A51: not is_widget_pressed 70
8A51: not is_widget_pressed 7
jf @Not_Pressed
return


:End

if
    0A51: is_widget_pressed 7
then
    
    if
        $Auto == true
    then
        gosub @Return
    end
    
    end_thread
end

return

 

______________________________________________________________

Link to comment
Share on other sites

@Gdzin i can't answer your question but i highly suggest you to not use global variable "$Car" on your script... use local variable "0@" instead..

 

- Your script is initiated with your player.. you should always check if your player is defined.. (maybe in your case "controllable" also)

- Don't forget to start with {Cleo.cs}..

- If you are trying to define some coordinates you may enter some values by putting const..end at the header..

 

{Cleo.cs}
//-----Maybe some descriptive things about your script-----//

const
0@= 1.23 //Player Coordinates X
1@= 4.56 //Player Coordinates Y
2@= 7.89 //Player Coordinates Z
end

Main Script..
...
..
.

 

Edited by ArmanCan
Link to comment
Share on other sites

As ArmanCan said it is highly recommended to not use global variables in cleo stripts, as main.scm and other scripts might also use same variables to other purposes.

 

The code is more complicated than it should. Try use less labels, if some code is used once just put it into desired location.

I also suggest to get familiar with cleo_call and cleo_return opcodes (0AB1, 0AB2) as they provide some way to encapsulate code in logical blocks and have real local variables.

 

This section looks suspicious for me:

        gosub @Return
        gosub @Not_Pressed
        goto @1

Seems like instead of returning from the routine you just jump back into main loop, so call stack keeps growing.

 

If you have problems with figuring out what is going on it the script add some debug prints like:

0AD1: show_formatted_text_highpriority "DEBUG %d" time 2000 TimerA

 

Edited by MiranDMC
Link to comment
Share on other sites

I don't use cleo_call because the version of cleo scipt mobile doesn't have that, and in terms of "{Cleo .csi}", I just didn't put it here because it would show the addresses, and I use this gosub so the code is more optimized and doesn't keep repeating code all the time, and yes you are right, when I use these variables there are times that it gives error, I use it because I have bad memory and I save what each variable does, that's why I put it custom, so I'm going to start using the const

Link to comment
Share on other sites

A "sub script" (script block that was called by gosub command) must end with return

 

But in that time "sub script" a goto @1 command should lead the code out, to the regular script loop

that's a mistake

:Time
Timera = 0
while Timera < 1000             
    
    wait 0
    
    if
        0A51: is_widget_pressed 8
    then
    end
    
    if
        0A51: is_widget_pressed 70
    then
        gosub @Return
        gosub @Not_Pressed
        goto @1  <------------------- here
    end
    
    gosub @End
                           
end
return

 

One more mistake: opcode 0811: is not a condition

    if and
        0811: $Car = actor $PLAYER_ACTOR used_car
        $Car >= 0 
    then
        0407: store_coords_to $PlayerX $PlayerY $PlayerZ from_car $Car with_offset 0.0 0.0 -1.0
    else
        04C4: store_coords_to $PlayerX $PlayerY $PlayerZ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 -1.0
    end

 

 

Maybe it's not the answer for your question

For your question i confirm to MiranDMC, " add some debug prints"

I prefer draw_text codes

Spoiler
:Time
Timera = 0
while Timera < 1000             
    
    wait 0
    03F0: enable_text_draw 1
    045A: draw_text_1number 20.0 230.0 GXT 'NUMBER' number Timera    
    if
        0A51: is_widget_pressed 8
    then
    end
    
    if
        0A51: is_widget_pressed 70
    then
        gosub @Return
        gosub @Not_Pressed
        goto @1
    end
    
    gosub @End
                           
end
return

 

 

In addition, we can't test the script, because the memory adresses are unknown

 

 

Edited by ZAZ
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.