EAZYJ Posted Sunday at 03:15 PM Share Posted Sunday at 03:15 PM Hello guys, Here's what I'm trying to do, but I'm not very familiar with arrays yet. I wanted to make various spawn locations where enemies would come out of randomly: Quote $ENEMY_SPAWN_X[1] = 2498.4067 $ENEMY_SPAWN_Y[1] = -1642.39 $ENEMY_SPAWN_Z[1] = 15.8359 $ENEMY_SPAWN_A[1] = 175.0 $ENEMY_SPAWN_X[2] = 2513.626 $ENEMY_SPAWN_Y[2] = -1650.3113 $ENEMY_SPAWN_Z[2] = 13.3557 $ENEMY_SPAWN_A[2] = 135.0 $ENEMY_SPAWN_X[3] = 2524.5352 $ENEMY_SPAWN_Y[3] = -1658.4711 $ENEMY_SPAWN_Z[3] = 14.4935 $ENEMY_SPAWN_A[3] = 90.0 etc... I have made the script to make them spawn already, now how do I declare that as an array because I get this message from Sanny Builder whenever I compile: Quote "Variable $ENEMY_SPAWN_X is not declared as an array" The error is at this line: Quote 80C2: not sphere_onscreen $ENEMY_SPAWN_X[[email protected]] $ENEMY_SPAWN_Y[[email protected]] $ENEMY_SPAWN_Z[[email protected]] radius 2.0 Thanks for any help. Link to comment Share on other sites More sharing options...
OrionSR Posted Sunday at 05:34 PM Share Posted Sunday at 05:34 PM (edited) The format shown below is required when using variables in the array index. In this example 8 is the number of elements in the array, and f denotes a float. 80C2: not sphere_onscreen $ENEMY_SPAWN_X([email protected],8f) $ENEMY_SPAWN_Y([email protected],8f) $ENEMY_SPAWN_Z([email protected],8f) radius 2.0 If you do not allocate these global variables carefully a cleo script using these arrays will severely corrupt your global variables. The array elements will bypass the protection Sanny usually offers to critical named CustomVariables. Arrays are tough to code in cleo scripts. Main.scm "owns" all global variables, and the 32 local variables available to cleo scripts doesn't leave much room for arrays of any size. Can you code this as a custom mission? Added: The usual solution to conserving variable usage in a situation like yours is to use the random number with a jumptable/switch case format to assign the values to only 4 variables as needed. Note: Local variables can be assigned custom names using the CONST..END construct. Inventing custom global variable names is very likely to cause corruption to saved data. Edited Sunday at 05:54 PM by OrionSR EAZYJ 1 Link to comment Share on other sites More sharing options...
Jack Posted Sunday at 09:04 PM Share Posted Sunday at 09:04 PM I'm sorry for the intrusion. We could create arrays in cleo differently (without the use of global variables). It's quite safe way and pretty much popular by now: Spoiler 0AC6: [email protected] = label @coordArray pointer while true wait 0 0209: [email protected] = random_int_in_ranges 0 3 // 0, 1, 2 [email protected] *= 4 // X, Y, Z, A ---> 4 elements [email protected] *= 4 // float ---> size 4 0085: [email protected] = [email protected] // coordArray 005A: [email protected] += [email protected] [email protected] += 0 0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0 [email protected] += 4 0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0 [email protected] += 4 0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0 [email protected] += 4 0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0 // example if 0248: model #MALE01 available then if 856D: NOT actor [email protected] defined then 009A: [email protected] = create_actor_pedtype 4 model #MALE01 at [email protected] [email protected] [email protected] 0173: set_actor [email protected] Z_angle_to [email protected] 01C2: remove_references_to_actor [email protected] end else 0247: load_model #MALE01 // 038B: load_requested_models end end :coordArray hex 82 26 1C 45 // 0x451C2682 // 2498.4067 // $ENEMY_SPAWN_X[0] 0 7B 4C CD C4 // 0xC4CD4C7B // -1642.39 // $ENEMY_SPAWN_Y[0] 1 D9 5F 7D 41 // 0x417D5FD9 // 15.8359 // $ENEMY_SPAWN_Z[0] 2 00 00 2F 43 // 0x432F0000 // 175.0 // $ENEMY_SPAWN_A[0] 3 04 1A 1D 45 // 0x451D1A04 // 2513.626 // $ENEMY_SPAWN_X[1] 4 F6 49 CE C4 // 0xC4CE49F6 // -1650.3113 // $ENEMY_SPAWN_Y[1] 5 F2 B0 55 41 // 0x4155B0F2 // 13.3557 // $ENEMY_SPAWN_Z[1] 6 00 00 07 43 // 0x43070000 // 135.0 // $ENEMY_SPAWN_A[1] 7 90 C8 1D 45 // 0x451DC890 // 2524.5352 // $ENEMY_SPAWN_X[2] 8 13 4F CF C4 // 0xC4CF4F13 // -1658.4711 // $ENEMY_SPAWN_Y[2] 9 60 E5 67 41 // 0x4167E560 // 14.4935 // $ENEMY_SPAWN_Z[2] 10 00 00 B4 42 // 0x42B40000 // 90.0 // $ENEMY_SPAWN_A[2] 11 end or with the direct input of float data into the hex block (same method with a slightly different approach): Spoiler 0AC6: [email protected] = label @coordArray pointer while true wait 0 0085: [email protected] = [email protected] [email protected] += 0 0A8C: write_memory [email protected] size 4 value 2498.4067 virtual_protect 0 [email protected] += 4 0A8C: write_memory [email protected] size 4 value -1642.39 virtual_protect 0 [email protected] += 4 0A8C: write_memory [email protected] size 4 value 15.8359 virtual_protect 0 [email protected] += 4 0A8C: write_memory [email protected] size 4 value 175.0 virtual_protect 0 [email protected] += 4 0A8C: write_memory [email protected] size 4 value 2513.626 virtual_protect 0 [email protected] += 4 0A8C: write_memory [email protected] size 4 value -1650.3113 virtual_protect 0 [email protected] += 4 0A8C: write_memory [email protected] size 4 value 13.3557 virtual_protect 0 [email protected] += 4 0A8C: write_memory [email protected] size 4 value 135.0 virtual_protect 0 [email protected] += 4 0A8C: write_memory [email protected] size 4 value 2524.5352 virtual_protect 0 [email protected] += 4 0A8C: write_memory [email protected] size 4 value -1658.4711 virtual_protect 0 [email protected] += 4 0A8C: write_memory [email protected] size 4 value 14.4935 virtual_protect 0 [email protected] += 4 0A8C: write_memory [email protected] size 4 value 90.0 virtual_protect 0 0209: [email protected] = random_int_in_ranges 0 3 // 0, 1, 2 [email protected] *= 4 // X, Y, Z, A ---> 4 elements [email protected] *= 4 // float ---> size 4 0085: [email protected] = [email protected] // coordArray 005A: [email protected] += [email protected] [email protected] += 0 0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0 [email protected] += 4 0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0 [email protected] += 4 0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0 [email protected] += 4 0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0 // example: if 0248: model #MALE01 available then if 856D: NOT actor [email protected] defined then 009A: [email protected] = create_actor_pedtype 4 model #MALE01 at [email protected] [email protected] [email protected] 0173: set_actor [email protected] Z_angle_to [email protected] 01C2: remove_references_to_actor [email protected] end else 0247: load_model #MALE01 // 038B: load_requested_models end end :coordArray hex // user inputed data end This way we could use arrays for storing any type of data including handles of peds, vehicles, objects... all kinds of possibilities. ... just a thought. EAZYJ 1 Wanted Level Editor Gore Level Effect [III] My YouTube Channel Link to comment Share on other sites More sharing options...
EAZYJ Posted Sunday at 10:52 PM Author Share Posted Sunday at 10:52 PM Thanks a lot for the detailed explanations guys! Although I don't really have a high level in coding to get a hold of all of it but I can see the points you're making. Now I should mention that I am scripting my mission on the main.scm and I don't think I'll be having any cleo using an array but it's always good to know. So would it be safer to switch to local variables then? By the way, another question: can I use those variables for the actors as well? Here's what I'm trying to achieve (this is sketchy but it's mostly to give you an idea) Quote :SPAWNING_ON wait 0 if $SPAWNING == 1 jf @SPAWNING_ADJUST if not $TOTAL_ENEMIES > 10 jf @SPAWNING_ADJUST 0209: [email protected] = random_int_in_ranges 1 11 if 80C2: not sphere_onscreen $ENEMY_SPAWN_X([email protected],11f) $ENEMY_SPAWN_Y([email protected],11f) $ENEMY_SPAWN_Z([email protected],11f) radius 2.0 jf @SPAWNING_ADJUST $ENEMY([email protected],15i) = Actor.Create(Mission1, #SWAT, $ENEMY_SPAWN_X([email protected],11f), $ENEMY_SPAWN_Y([email protected],11f), $ENEMY_SPAWN_Z([email protected],11f)) Actor.Angle($ENEMY([email protected],15i)) = $ENEMY_SPAWN_A([email protected],11f) 05E2: AS_actor $ENEMY([email protected],15i) kill_actor $PLAYER_ACTOR 04C4: store_coords_to $TEMPVAR_FLOAT_1 $TEMPVAR_FLOAT_2 $TEMPVAR_FLOAT_3 from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0 0603: AS_actor $ENEMY([email protected],15i) goto_point_any_means $TEMPVAR_FLOAT_1 $TEMPVAR_FLOAT_2 $TEMPVAR_FLOAT_3 mode 6 use_car -1 [email protected] += 1 $TOTAL_ENEMIES += 1 :SPAWNING_ADJUST wait 0 if Actor.Dead($ENEMY([email protected],15i)) jf @SPAWNING_ON Actor.RemoveReferences($ENEMY([email protected],15i)) [email protected] += -1 $TOTAL_ENEMIES += -1 jump @SPAWNING_ON Link to comment Share on other sites More sharing options...
OrionSR Posted Monday at 12:55 AM Share Posted Monday at 12:55 AM 1 hour ago, EAZYJ said: Now I should mention that I am scripting my mission on the main.scm Well, mentioning it a bit sooner would have saved you warning, but objections withdrawn. You own the globals in your custom main. EAZYJ 1 Link to comment Share on other sites More sharing options...