Jump to content

array crash


HeresOtis

Recommended Posts

This is part of the code. The rest of the code is correct. I loaded the models. I press a key and it spawns a police. Once police is spawned it adds 1 to 5@ (array) and jumps back to "if key press loop". When I press the key again it crashes. 5@ = 0 is at the top of the script, which is not shown.

 

 

:PURSUIT_5097wait 0  if   not Actor.Dead(1@)else_jump @PURSUIT_8516 if  9 > 5@ else_jump @PURSUIT_8493 if  5@ == 0 else_jump @PURSUIT_5400 wait 100 02C1: store_to 27@ 28@ 29@ car_path_coords_closest_to 27@ 28@ 29@ 4@(5@,10i) = Car.Create(2@, 27@, 28@, 29@)0129: 6@(5@,10i) = create_actor_pedtype 6 model 25@ in_car 4@(5@,10i) driverseat 01B2: give_actor 6@(5@,10i) weapon 22 ammo 99999 // Load the weapon model before using this 0350: set_actor 6@(5@,10i) maintain_position_when_attacked 1 0397: enable_car 4@(5@,10i) siren 1 07F8: car 4@(5@,10i) follow_car 0@ radius 13.5 Car.SetMaxSpeed(4@(5@,10i), 34.0)0423: set_car 4@(5@,10i) improved_handling_to 1.5 // (float) 00AE: set_car 4@(5@,10i) traffic_behaviour_to 2 Car.SetImmunities(4@(5@,10i), 0, 0, 0, 0, 0)067F: set_car 4@(5@,10i) lights 2 7@(5@,10i) = Marker.CreateAboveActor(6@(5@,10i))07E0: set_marker 7@(5@,10i) type_to 1 03E5: show_text_box 'SCN10' 5@ += 1 wait 500 jump @PURSUIT_1473 :PURSUIT_5400wait 0 if   not Actor.Dead(1@)else_jump @PURSUIT_8516 if  5@ == 1else_jump @PURSUIT_5685wait 100  02C1: store_to 27@ 28@ 29@ car_path_coords_closest_to 27@ 28@ 29@ 4@(5@,10i) = Car.Create(2@, 27@, 28@, 29@)0129: 6@(5@,10i) = create_actor_pedtype 6 model 25@ in_car 4@(5@,10i) driverseat 01B2: give_actor 6@(5@,10i) weapon 22 ammo 99999 // Load the weapon model before using this 0350: set_actor 6@(5@,10i) maintain_position_when_attacked 1 0397: enable_car 4@(5@,10i) siren 1 07F8: car 4@(5@,10i) follow_car 0@ radius 13.5 Car.SetMaxSpeed(4@(5@,10i), 34.0)0423: set_car 4@(5@,10i) improved_handling_to 1.5 // (float) 00AE: set_car 4@(5@,10i) traffic_behaviour_to 2 Car.SetImmunities(4@(5@,10i), 0, 0, 0, 0, 0)067F: set_car 4@(5@,10i) lights 2 7@(5@,10i) = Marker.CreateAboveActor(6@(5@,10i))07E0: set_marker 7@(5@,10i) type_to 1 03E5: show_text_box 'SCN10' 5@ += 1 wait 500 jump @PURSUIT_1473 

 

Link to comment
Share on other sites

 

This is part of the code. The rest of the code is correct. I loaded the models. I press a key and it spawns a police. Once police is spawned it adds 1 to 5@ (array) and jumps back to "if key press loop". When I press the key again it crashes. 5@ = 0  is at the top of the script, which is not shown.

 

 

to can spawn 3 cars by array needs to reserve 3 locals

 

index of 5@ = 0

4@(5@,10i) = Car.Create

 

 

index of 5@ = 1

4@(5@,10i) = Car.Create

is equal to 5@ = Car.Create

 

index of 5@ = 2

4@(5@,10i) = Car.Create

is equal to 6@ = Car.Create

 

 

it needs to reserve 4@, 5@ and 6@ for the cars

you can also command each car by using the simple local 6@ instaead by array construct: index of 5@ = 2 / 4@(5@,10i) = Car.Create

 

it crashes if you use 5@ as index and try to spawn 6@(5@,10i) as actor

to handle 10 cars, 10 actors, 10 markers needs 30 locals

 

read ARRAYS

 

6@[index 0] = father

6@[index 1] = mother

6@[index 2] = son

6@[index 3] = doughter

6@[index 4] = Carl

 

the assignment of ascending index values uses new locals in ascending order

 

6@ = father

7@ = mother

8@ = son

9@ = doughter

10@ = Carl

Edited by ZAZ
Link to comment
Share on other sites

Do you think that I should use Opcode 0A92 to create a new thread specifically for all the cars and actors, since I need to use so many opcodes?

Link to comment
Share on other sites

Do you think that I should use Opcode 0A92 to create a new thread specifically for all the cars and actors, since I need to use so many opcodes?

This isn't big and I know this is only a part. A thread is enough.

Link to comment
Share on other sites

 

Do you think that I should use Opcode 0A92 to create a new thread specifically for all the cars and actors, since I need to use so many opcodes?

it can be a solution to can use more locals

but at first you must calculate how many locals are really neccesary

 

i recomand to reduce the array item amount to 8 instead 10

 

if8 > 31@else_jump @PURSUIT_8493so use use 31@ as index varuse 0@(31@,10i) = Car.Create and reserve 0@ till 7@ for carsuse 0129: 8@(31@,10i)= create_actor and reserve 8@ till 15@ for actorsuse 16@(31@,10i) = Marker.CreateAboveActor and reserve 16@ till 23@ for markers24@ for car model id25@ for actor model iduse 27@ 28@ 29@ to read coords30@ for player_car

 

get then the script working in this way

later you can think about if you wanna handle 10 items

 

 

with 10 it needs 30 locals, then 30@ for player_car, 31@ for array index

no local for model id

no locals for coords

 

if10 > 31@else_jump @PURSUIT_84930@(31@,10i) = Car.Create(#FBIRANCH, ?, ?, ?)0129: 10@(31@,10i) = create_actor_pedtype 6 model #FBI in_car 0@(31@,10i) driverseat01B2: give_actor 10@(31@,10i) weapon 22 ammo 99999 // Load the weapon model before using this0350: set_actor 10@(31@,10i) maintain_position_when_attacked 10397: enable_car 0@(31@,10i) siren 107F8: car 0@(31@,10i) follow_car 30@ radius 13.5Car.SetMaxSpeed(0@(31@,10i), 34.0)0423: set_car 0@(31@,10i) improved_handling_to 1.5 // (float)00AE: set_car 0@(31@,10i) traffic_behaviour_to 2Car.SetImmunities(0@(31@,10i), 0, 0, 0, 0, 0)067F: set_car 0@(31@,10i) lights 220@(31@,10i) = Marker.CreateAboveActor(10@(31@,10i))07E0: set_marker 20@(31@,10i) type_to 103E5: show_text_box 'SCN10'31@ += 1jump @PURSUIT_1473

 

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.