Advertisement
Guest User

Why Arrays Are Useful in Choicescript

a guest
Apr 27th, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.31 KB | None | 0 0
  1. *comment here's our simple inventory:
  2. *temp inv_slot_1 "Steel sword"
  3. *temp inv_slot_2 "Wooden shield"
  4. *temp inv_slot_3 "Magic potion"
  5. *temp inv_slot_4 "Health potion"
  6. *temp inv_slot_5 "Rope"
  7. *temp inv_slot_6 "nothing"
  8. *temp inv_slot_7 "nothing"
  9. *temp inv_slot_8 "nothing"
  10. *temp inv_slot_9 "nothing"
  11. *temp inv_slot_10 "nothing"
  12.  
  13. *comment here's a basic and pretty standard way of displaying what's in our inventory:
  14. 1st Method #1
  15. *line_break
  16. *line_break
  17. *if (inv_slot_1 != "nothing")
  18. ${inv_slot_1},
  19. *if (inv_slot_2 != "nothing")
  20. ${inv_slot_2},
  21. *if (inv_slot_3 != "nothing")
  22. ${inv_slot_3},
  23. *if (inv_slot_4 != "nothing")
  24. ${inv_slot_4},
  25. *if (inv_slot_5 != "nothing")
  26. ${inv_slot_5},
  27. *if (inv_slot_6 != "nothing")
  28. ${inv_slot_6},
  29. *if (inv_slot_7 != "nothing")
  30. ${inv_slot_7},
  31. *if (inv_slot_8 != "nothing")
  32. ${inv_slot_8},
  33. *if (inv_slot_9 != "nothing")
  34. ${inv_slot_9},
  35. *if (inv_slot_10 != "nothing")
  36. ${inv_slot_10},
  37.  
  38. *comment here's another way that uses a loop:
  39. *page_break
  40. 2nd Method #1
  41. *line_break
  42. *line_break
  43. *label print_inventory
  44. *temp n 0
  45. *temp current_inv_item
  46. *label print_inventory_loop
  47. *set n + 1
  48. *set current_inv_item {"inv_slot_"&n}
  49. *if (current_inv_item != "nothing")
  50. ${current_inv_item},
  51. *if (n < 10)
  52. *goto print_inventory_loop
  53.  
  54. *comment both produce exactly the same result, so which do you think is better?
  55. *comment in this particular case, it's fair to say neither is overly advantageous
  56. *comment But wait! Let's try that again with 50 item slots...
  57.  
  58. *temp inv_slot_1 "Steel sword"
  59. *temp inv_slot_2 "Wooden shield"
  60. *temp inv_slot_3 "Magic potion"
  61. *temp inv_slot_4 "Health potion"
  62. *temp inv_slot_5 "Rope"
  63. *temp inv_slot_6 "Wizard Staff"
  64. *temp inv_slot_7 "Glowing Orb"
  65. *temp inv_slot_8 "Dragon Egg"
  66. *temp inv_slot_9 "55 Gold Pieces"
  67. *temp inv_slot_10 "Gold Locket"
  68. *temp inv_slot_11 "Blunt Axe"
  69. *temp inv_slot_12 "Sharp Dagger"
  70. *temp inv_slot_13 "Boots of Speed"
  71. *temp inv_slot_14 "Etc..."
  72. *temp inv_slot_15 "nothing"
  73. *temp inv_slot_16 "nothing"
  74. *temp inv_slot_17 "nothing"
  75. *temp inv_slot_18 "nothing"
  76. *temp inv_slot_19 "nothing"
  77. *temp inv_slot_20 "nothing"
  78. *temp inv_slot_21 "nothing"
  79. *temp inv_slot_22 "nothing"
  80. *temp inv_slot_23 "nothing"
  81. *temp inv_slot_24 "nothing"
  82. *temp inv_slot_25 "nothing"
  83. *temp inv_slot_26 "nothing"
  84. *temp inv_slot_27 "nothing"
  85. *temp inv_slot_28 "nothing"
  86. *temp inv_slot_29 "nothing"
  87. *temp inv_slot_30 "nothing"
  88. *temp inv_slot_31 "nothing"
  89. *temp inv_slot_32 "nothing"
  90. *temp inv_slot_33 "nothing"
  91. *temp inv_slot_34 "nothing"
  92. *temp inv_slot_35 "nothing"
  93. *temp inv_slot_36 "nothing"
  94. *temp inv_slot_37 "nothing"
  95. *temp inv_slot_38 "nothing"
  96. *temp inv_slot_39 "nothing"
  97. *temp inv_slot_40 "nothing"
  98. *temp inv_slot_41 "nothing"
  99. *temp inv_slot_42 "nothing"
  100. *temp inv_slot_43 "nothing"
  101. *temp inv_slot_44 "nothing"
  102. *temp inv_slot_45 "nothing"
  103. *temp inv_slot_46 "nothing"
  104. *temp inv_slot_47 "nothing"
  105. *temp inv_slot_48 "nothing"
  106. *temp inv_slot_49 "nothing"
  107. *temp inv_slot_50 "nothing"
  108.  
  109. *comment here's the ammended code for our first method:
  110. *page_break
  111. 1st Method #2
  112. *line_break
  113. *line_break
  114. *if (inv_slot_1 != "nothing")
  115. ${inv_slot_1},
  116. *if (inv_slot_2 != "nothing")
  117. ${inv_slot_2},
  118. *if (inv_slot_3 != "nothing")
  119. ${inv_slot_3},
  120. *if (inv_slot_4 != "nothing")
  121. ${inv_slot_4},
  122. *if (inv_slot_5 != "nothing")
  123. ${inv_slot_5},
  124. *if (inv_slot_6 != "nothing")
  125. ${inv_slot_6},
  126. *if (inv_slot_7 != "nothing")
  127. ${inv_slot_7},
  128. *if (inv_slot_8 != "nothing")
  129. ${inv_slot_8},
  130. *if (inv_slot_9 != "nothing")
  131. ${inv_slot_9},
  132. *if (inv_slot_10 != "nothing")
  133. ${inv_slot_10},
  134. *if (inv_slot_11 != "nothing")
  135. ${inv_slot_11},
  136. *if (inv_slot_12 != "nothing")
  137. ${inv_slot_12},
  138. *if (inv_slot_13 != "nothing")
  139. ${inv_slot_13},
  140. *if (inv_slot_14 != "nothing")
  141. ${inv_slot_14},
  142. *if (inv_slot_15 != "nothing")
  143. ${inv_slot_15},
  144. *if (inv_slot_16 != "nothing")
  145. ${inv_slot_16},
  146. *if (inv_slot_17 != "nothing")
  147. ${inv_slot_17},
  148. *if (inv_slot_18 != "nothing")
  149. ${inv_slot_18},
  150. *if (inv_slot_19 != "nothing")
  151. ${inv_slot_19},
  152. *if (inv_slot_20 != "nothing")
  153. ${inv_slot_20},
  154. *if (inv_slot_21 != "nothing")
  155. ${inv_slot_21},
  156. *if (inv_slot_22 != "nothing")
  157. ${inv_slot_22},
  158. *if (inv_slot_23 != "nothing")
  159. ${inv_slot_23},
  160. *if (inv_slot_24 != "nothing")
  161. ${inv_slot_24},
  162. *if (inv_slot_25 != "nothing")
  163. ${inv_slot_25},
  164. *if (inv_slot_26 != "nothing")
  165. ${inv_slot_26},
  166. *if (inv_slot_27 != "nothing")
  167. ${inv_slot_27},
  168. *if (inv_slot_28 != "nothing")
  169. ${inv_slot_28},
  170. *if (inv_slot_29 != "nothing")
  171. ${inv_slot_29},
  172. *if (inv_slot_30 != "nothing")
  173. ${inv_slot_30},
  174. *if (inv_slot_31 != "nothing")
  175. ${inv_slot_31},
  176. *if (inv_slot_32 != "nothing")
  177. ${inv_slot_32},
  178. *if (inv_slot_33 != "nothing")
  179. ${inv_slot_33},
  180. *if (inv_slot_34 != "nothing")
  181. ${inv_slot_34},
  182. *if (inv_slot_35 != "nothing")
  183. ${inv_slot_35},
  184. *if (inv_slot_36 != "nothing")
  185. ${inv_slot_36},
  186. *if (inv_slot_37 != "nothing")
  187. ${inv_slot_37},
  188. *if (inv_slot_38 != "nothing")
  189. ${inv_slot_38},
  190. *if (inv_slot_39 != "nothing")
  191. ${inv_slot_39},
  192. *if (inv_slot_40 != "nothing")
  193. ${inv_slot_40},
  194. *if (inv_slot_41 != "nothing")
  195. ${inv_slot_41},
  196. *if (inv_slot_42 != "nothing")
  197. ${inv_slot_42},
  198. *if (inv_slot_43 != "nothing")
  199. ${inv_slot_43},
  200. *if (inv_slot_44 != "nothing")
  201. ${inv_slot_44},
  202. *if (inv_slot_45 != "nothing")
  203. ${inv_slot_45},
  204. *if (inv_slot_46 != "nothing")
  205. ${inv_slot_46},
  206. *if (inv_slot_47 != "nothing")
  207. ${inv_slot_47},
  208. *if (inv_slot_48 != "nothing")
  209. ${inv_slot_48},
  210. *if (inv_slot_49 != "nothing")
  211. ${inv_slot_49},
  212. *if (inv_slot_50 != "nothing")
  213. ${inv_slot_50},
  214.  
  215. *comment painful, right? Check out the ammended code for our second (loop utilizing) method:
  216. *page_break
  217. 2nd Method #2
  218. *line_break
  219. *line_break
  220. *label print_inventory_2
  221. *temp n 0
  222. *temp current_inv_item
  223. *label print_inventory_loop_2
  224. *set n + 1
  225. *set current_inv_item {"inv_slot_"&n}
  226. *if (current_inv_item != "nothing")
  227. ${current_inv_item},
  228. *if (n < 50)
  229. *goto print_inventory_loop_2
  230. *finish
  231.  
  232. *comment so, which one do you think scales better? :)
  233. *comment note that the only reason we needed to change the labels of this 2nd method this time round
  234. *comment was due to them already existing from the first time round - we would actually only need to
  235. *comment ever change the (n < 50) bit to however many slots we have, that's it!
  236. *comment we could even swap '50' out for a variable stored value like "item_count" if we wanted.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement