| 08-23-2007, 02:02 AM | #1 |
I have a system thing that I am almost done with a good portion of but would like to optimize it as much as possible... It calculates the Z of a number of points in the map and uses those as a replacement for GetLocationZ later on. Also I am getting an error in the ReturnZ function Custom Script JASS://==========BEGIN Z MAP CALCULATOR=========== //==========BEGIN Z MAP CALCULATOR=========== //==========BEGIN Z MAP CALCULATOR=========== constant function between_points takes nothing returns integer return 64 //Change to set more or fewer points recommended is 64 MUST be a factor of the max points on the map endfunction constant function lastpoint_x takes nothing returns integer return 10240 //set to the number of points in the x of the map found under Map Properties endfunction constant function lastpoint_y takes nothing returns integer return 10240 //set to the number of points in the y of the map found under Map Properties endfunction function ReturnZ takes location Z and returns real local integer dist = between_points() local integer X_Max = lastpoint_x() local integer Y_Max = lastpoint_y() local integer X = 0 local integer Y = 0 local integer ArrayNumber = 0 set X = GetLocationX(Z) set Y = GetLocationY(Z) if X < 1 then set X = RAbs(X) / dist else set X = (X + X_Max) / dist endif if Y < 1 then set Y = RAbs(Y) / dist else set Y = (Y + Y_Max) / dist endif set ArrayNumber = X+1*(Y_Max*2) + Y if ArrayNumber <= 8191 then return udg_Z_Value1[ArrayNumber] elseif (ArrayNumber > 8191) and (ArrayNumber <= (8191*2)) then return udg_Z_Value1[ArrayNumber] elseif (ArrayNumber > 8191*2) and (ArrayNumber <= (8191*3)) then return udg_Z_Value1[ArrayNumber] elseif (ArrayNumber > 8191*3) and (ArrayNumber <= (8191*4)) then return udg_Z_Value1[ArrayNumber] elseif (ArrayNumber > 8191*4) and (ArrayNumber <= (8191*5)) then return udg_Z_Value1[ArrayNumber] endif endfunction //==========END Z MAP CALCULATOR=========== //==========END Z MAP CALCULATOR=========== //==========END Z MAP CALCULATOR=========== JASS:function Set_Max_Array takes nothing returns nothing local integer dist = between_points() local integer X_Max = lastpoint_x() local integer Y_Max = lastpoint_y() local integer max = (X_Max / dist * 2) + (Y_Max / dist * 2) local integer I = 0 local integer Total = 0 loop set I = I+1 exitwhen I > max set udg_Extended[i] = I * 8191 endloop set Total = I * 8191 set udg_End_Array = max call ExecuteFunc("Set_Z_Map") endfunction function Set_Z_Map takes integer X_Max, integer Y_Max, integer Total, integer dist returns nothing local integer I = -1 local integer X = (X_Max*-1) local integer Y = (Y_Max*-1) local integer X2 = 0 local integer Y2 = 0 local integer ArrayNumber = 0 set udg_ZLocation = Location(X,Y)//Set first Z point loop set I = I+1 exitwhen I > udg_Extended[udg_End_Array] call MoveLocation(udg_ZLocation,X,Y) set ArrayNumber = X2+1*(Y_Max*2) + Y2 if ArrayNumber <= 8191 then set udg_Z_Value1[ArrayNumber] = GetLocationZ(udg_ZLocation) elseif (ArrayNumber > 8191) and (ArrayNumber <= (8191*2)) then set udg_Z_Value2[ArrayNumber] = GetLocationZ(udg_ZLocation) elseif (ArrayNumber > 8191*2) and (ArrayNumber <= (8191*3)) then set udg_Z_Value3[ArrayNumber] = GetLocationZ(udg_ZLocation) elseif (ArrayNumber > 8191*3) and (ArrayNumber <= (8191*4)) then set udg_Z_Value4[ArrayNumber] = GetLocationZ(udg_ZLocation) elseif (ArrayNumber > 8191*4) and (ArrayNumber <= (8191*5)) then set udg_Z_Value5[ArrayNumber] = GetLocationZ(udg_ZLocation) endif if X2 == X_Max*2 then set Y2 = Y2 + dist set X2 = 0 elseif X2 == X_Max*2 then set X2 = X2 + dist endif endloop endfunction //=========================================================================== function InitTrig_Set_Values_Init takes nothing returns nothing set gg_trg_Set_Values_Init = CreateTrigger( ) call TriggerAddAction( gg_trg_Set_Values_Init, function Set_Max_Array ) endfunction PS: im shure most of you are sick of mt and Z values by now but any help is apreciated |
| 08-23-2007, 06:28 AM | #2 |
JASS:
if ArrayNumber <= 8191 then
return udg_Z_Value1[ArrayNumber]
elseif (ArrayNumber > 8191) and (ArrayNumber <= (8191*2)) then
return udg_Z_Value1[ArrayNumber]
elseif (ArrayNumber > 8191*2) and (ArrayNumber <= (8191*3)) then
return udg_Z_Value1[ArrayNumber]
elseif (ArrayNumber > 8191*3) and (ArrayNumber <= (8191*4)) then
return udg_Z_Value1[ArrayNumber]
elseif (ArrayNumber > 8191*4) and (ArrayNumber <= (8191*5)) then
return udg_Z_Value1[ArrayNumber]
endif
udg_Z_Value1, udg_Z_Value1, udg_Z_Value1 ??? udg_Z_Value1, udg_Z_Value2, udg_Z_Value3 <--- By the way this is slower than extended arrays, not to mention untested. One more thing: JASS:constant function between_points takes nothing returns integer return 64 //Change to set more or fewer points recommended is 64 MUST be a factor of the max points on the map endfunction constant function lastpoint_x takes nothing returns integer return 10240 //set to the number of points in the x of the map found under Map Properties endfunction constant function lastpoint_y takes nothing returns integer return 10240 //set to the number of points in the y of the map found under Map Properties endfunction should be: JASS:globals constant integer between_points = 64 constant integer lastpoint_x = 10240 constant integer lastpoint_y = 10240 endglobals |
| 08-23-2007, 07:24 AM | #3 |
He's using a Mac. No globals blocks. |
| 08-23-2007, 07:25 AM | #4 |
You forgot to mention the cause of the error in ReturnZ. It's because this: JASS:local integer X = 0 local integer Y = 0 Should be: JASS:local real X = 0 local real Y = 0 Because you set them to a real value: JASS:set X = GetLocationX(Z) set Y = GetLocationY(Z) And to do that what cohadar said, you need to have JassNewGenPack. |
| 08-23-2007, 10:59 PM | #5 |
That didn't fix the error still says expected ' also I declared the constants in custom script to make them function the same way as if I used a constant block... It shouldn't be THAT much slower...Also why would my if then elseif be slower then an extended array it functions in the same way and has to parse through less functions... |
