Loading...
  OR  Zero-K Name:    Password:   

Post edit history

Minefield Grid Widget by Autowar

To display differences between versions, select one or more edits in the list using checkboxes and click "diff selected"
Post edit history
Date Editor Before After
4/15/2015 11:30:20 AMDErank[2up]knorke before revert after revert
4/15/2015 11:28:59 AMDErank[2up]knorke before revert after revert
4/15/2015 11:28:45 AMDErank[2up]knorke before revert after revert
4/15/2015 11:27:44 AMDErank[2up]knorke before revert after revert
Before After
1 [spoiler]
2 \n
3 [b]function widget:KeyPress(key, mods, isRepeat) 1 [b]function widget:KeyPress(key, mods, isRepeat)
4 --somehow "D" key id is 100 2 --somehow "D" key id is 100
5 local dKey=100[/b] 3 local dKey=100[/b]
6 D key is 100 because https://github.com/spring/spring/blob/develop/cont/base/springcontent/LuaHandler/Utilities/keysym.lua 4 D key is 100 because https://github.com/spring/spring/blob/develop/cont/base/springcontent/LuaHandler/Utilities/keysym.lua
7 => 5 =>
8 [b]include("keysym.h.lua") 6 [b]include("keysym.h.lua")
9 local dKey = KEYSYMS.D[/b] 7 local dKey = KEYSYMS.D[/b]
10 \n 8 \n
11 Your commands are always given with {"shift"}) no matter if player pressed that key or not. 9 Your commands are always given with {"shift"}) no matter if player pressed that key or not.
12 \n 10 \n
13 Might want to look into: 11 Might want to look into:
14 -custom commands 12 -custom commands
15 -whatever zK does for hotkey system 13 -whatever zK does for hotkey system
16 \n 14 \n
17 \n 15 \n
18 \n 16 \n
19 [b]local tickAOE = 196 --armtick 17 [b]local tickAOE = 196 --armtick
20 ... 18 ...
21 \n 19 \n
22 if spGetUnitDefID(selectedUnits[i]) == UnitDefNames["armtick"].id then 20 if spGetUnitDefID(selectedUnits[i]) == UnitDefNames["armtick"].id then
23 unitAOE=tickAOE 21 unitAOE=tickAOE
24 elseif spGetUnitDefID(selectedUnits[i]) == UnitDefNames["corroach"].id then 22 elseif spGetUnitDefID(selectedUnits[i]) == UnitDefNames["corroach"].id then
25 unitAOE=roachAOE 23 unitAOE=roachAOE
26 elseif spGetUnitDefID(selectedUnits[i]) == UnitDefNames["corsktl"].id then 24 elseif spGetUnitDefID(selectedUnits[i]) == UnitDefNames["corsktl"].id then
27 unitAOE=skuttleAOE 25 unitAOE=skuttleAOE
28 elseif spGetUnitDefID(selectedUnits[i]) == UnitDefNames["blastwing"].id then 26 elseif spGetUnitDefID(selectedUnits[i]) == UnitDefNames["blastwing"].id then
29 unitAOE=blastwingAOE[/b] 27 unitAOE=blastwingAOE[/b]
30 \n 28 \n
31 -same thing multiple times: spGetUnitDefID(selectedUnits[i]) 29 -same thing multiple times: spGetUnitDefID(selectedUnits[i])
32 -the conditons look messy, the unit's name are not so lost in all the ([]=][[){]) 30 -the conditons look messy, the unit's name are not so lost in all the ([]=][[){])
33 \n 31 \n
34 Imo nicer to read like: 32 Imo nicer to read like:
35 [b] 33 [b]
36 selectedUnitName = UnitDefs[spGetUnitDefID(selectedUnits[i])] 34 selectedUnitName = UnitDefs[spGetUnitDefID(selectedUnits[i])]
37 if (selectedUnitName == "corroach") then 35 if (selectedUnitName == "corroach") then
38 unitAOE=roachAOE 36 unitAOE=roachAOE
39 elseif (selectedUnitName == "corskt") 37 elseif (selectedUnitName == "corskt")
40 then unitAOE=skuttleAOE 38 then unitAOE=skuttleAOE
41 elseif (selectedUnitName == "blastwing") then 39 elseif (selectedUnitName == "blastwing") then
42 unitAOE=blastwingAOE 40 unitAOE=blastwingAOE
43 end 41 end
44 [/b] 42 [/b]
45 \n 43 \n
46 \n 44 \n
47 BUT: 45 BUT:
48 => Lua can read unit & weapon defs: https://springrts.com/wiki/Lua_UnitDefs , https://springrts.com/wiki/Lua_WeaponDefs 46 => Lua can read unit & weapon defs: https://springrts.com/wiki/Lua_UnitDefs , https://springrts.com/wiki/Lua_WeaponDefs
49 \n 47 \n
50 And/or use a table instead of the if-chain like: 48 And/or use a table instead of the if-chain like:
51 [b] 49 [b]
52 unitsSeperationDistance = 50 unitsSeperationDistance =
53 { 51 {
54 [UnitDefNames["blastwing"].id] = 50, 52 [UnitDefNames["blastwing"].id] = 50,
55 [UnitDefNames["corsktl"].id] = 100, 53 [UnitDefNames["corsktl"].id] = 100,
56 ... 54 ...
57 }[/b] 55 }[/b]
58 \n 56 \n
59 \n 57 \n
60 \n 58 \n
61 This is 25 times similiar thing: 59 This is 25 times similiar thing:
62 [b] 60 [b]
63 if i==1 then 61 if i==1 then
64 x,y,z = spGetUnitPosition(selectedUnits[i]) 62 x,y,z = spGetUnitPosition(selectedUnits[i])
65 spGiveOrderToUnit(selectedUnits[i], CMD_MOVE, {x,0,z}, {"shift"}) 63 spGiveOrderToUnit(selectedUnits[i], CMD_MOVE, {x,0,z}, {"shift"})
66 elseif i==2 then 64 elseif i==2 then
67 spGiveOrderToUnit(selectedUnits[i], CMD_MOVE, {x,0,z+unitAOE}, {"shift"}) 65 spGiveOrderToUnit(selectedUnits[i], CMD_MOVE, {x,0,z+unitAOE}, {"shift"})
68 ... 66 ...
69 elseif i==25 then -- 67 elseif i==25 then --
70 spGiveOrderToUnit(selectedUnits[i], CMD_MOVE, {x+(unitAOE*2),0,z-(unitAOE*2)}, {"shift"}) 68 spGiveOrderToUnit(selectedUnits[i], CMD_MOVE, {x+(unitAOE*2),0,z-(unitAOE*2)}, {"shift"})
71 [/b] 69 [/b]
72 \n 70 \n
73 Find a better way to convert the unit's number i to X-Z coordinates. 71 Find a better way to convert the unit's number i to X-Z coordinates.
74 \n 72 \n
75 Something along: 73 Something along:
76 [b] 74 [b]
77 function getXZ(i) 75 function getXZ(i)
78 local size = 4 76 local size = 4
79 return i%size, math.floor(i/size) 77 return i%size, math.floor(i/size)
80 end 78 end
81 ... 79 ...
82 local x,z = getXZ (i) 80 local x,z = getXZ (i)
83 spGiveOrderToUnit(selectedUnits[i], CMD_MOVE, {x+(unitAOE*2),0,z-(unitAOE*2)} [/b] 81 spGiveOrderToUnit(selectedUnits[i], CMD_MOVE, {x+(unitAOE*2),0,z-(unitAOE*2)} [/b]
84 \n 82 \n
85 or 83 or
86 \n 84 \n
87 [b] 85 [b]
88 --define the coordinates of each position 86 --define the coordinates of each position
89 position [1] = {x=0,z=0} 87 position [1] = {x=0,z=0}
90 position [2] = {x=0,z=1} 88 position [2] = {x=0,z=1}
91 position [2] = {x=1,z=1} 89 position [2] = {x=1,z=1}
92 ... 90 ...
93 position [15] = {x=7,z=2} 91 position [15] = {x=7,z=2}
94 \n 92 \n
95 function getXZ (i) 93 function getXZ (i)
96 return position[i].x * seperationDistance, position[i].z * seperationDistance 94 return position[i].x * seperationDistance, position[i].z * seperationDistance
97 end 95 end
98 [/b] 96 [/b]
99 \n 97 \n
100 \n 98 \n
101 At top of file, all this: 99 At top of file, all this:
102 [b]local blablabla.Thing = blaThing[/b] 100 [b]local blablabla.Thing = blaThing[/b]
103 Maybe personal taste, but I find it not helpful. 101 Maybe personal taste, but I find it not helpful.
104 For performance it is mostly irrelevant except for drawing graphics etc. 102 For performance it is mostly irrelevant except for drawing graphics etc.
105 \n 103 \n
106 Half the local-things you do not even use. = Forms bad habits. 104 Half the local-things you do not even use. = Forms bad habits.
107 \n 105 \n
108 It only saves 5 characters to type sp VS Spring. 106 It only saves 5 characters to type sp VS Spring.
109 If removing those 5 letters are supposed to make a line of code look nicer, then the chance is there is too much things in one line anyway. 107 If removing those 5 letters are supposed to make a line of code look nicer, then the chance is there is too much things in one line anyway.
110 This is not even shorter: 108 This is not even shorter:
111 [b]CMD_MOVE = CMD.MOVE[/b] 109 [b]CMD_MOVE = CMD.MOVE[/b]
112 \n 110 \n
113 \n 111 \n
114 Declarations of constants or variables sometimes get mixed into the local-things, like here: 112 Declarations of constants or variables sometimes get mixed into the local-things, like here:
115 [b] 113 [b]
116 ... 114 ...
117 local CMD_MOVE = CMD.MOVE 115 local CMD_MOVE = CMD.MOVE
118 local CMD_UNIT_SET_TARGET = 34923 // this one is not like the others! 116 local CMD_UNIT_SET_TARGET = 34923 // this one is not like the others!
119 local CMD_GUARD = CMD.GUARD 117 local CMD_GUARD = CMD.GUARD
120 ... 118 ...
121 [/b] 119 [/b]
122 Looking at variables/constants is quick way to figure out what a script does: 120 Looking at variables/constants is quick way to figure out what a script does:
123 This makes them harder to spot. 121 This makes them harder to spot.
124 Also seeing the CMD_GUARD makes reader assume it will be used in script, but it is not. 122 Also seeing the CMD_GUARD makes reader assume it will be used in script, but it is not.
125 \n 123 \n
126 \n 124 \n
127 Risk to accidently create evil errors like: 125 Risk to accidently create evil errors like:
128 [b]local spGetMyTeamID = Spring.GetMyTeamID()[/b] 126 [b]local spGetMyTeamID = Spring.GetMyTeamID()[/b]
129 VS 127 VS
130 [b]local spGetMyTeamID = Spring.GetMyTeamID[/b] 128 [b]local spGetMyTeamID = Spring.GetMyTeamID[/b]
131 \n
132 [/spoiler]