Advertisement
Guest User

Array implementation in PS

a guest
May 9th, 2014
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.78 KB | None | 0 0
  1. Mindcraftmax59: so I was saying that "inventory" is used for simple things
  2. Rjbull_: ohh
  3. Mindcraftmax59: once you want to get an inventory with UI, you have to use more complex stuff
  4. Rjbull_: so... if I want one like minecraft
  5. Rjbull_: like, boxes at the bottom
  6. Mindcraftmax59: that one has a fixed number of slots
  7. Mindcraftmax59: that means that you want an array
  8. Mindcraftmax59: As I said, there are no native arrays in PS
  9. Mindcraftmax59: so we have come up with an implementation to fake them
  10. Mindcraftmax59: (we = I and Arisilde)
  11. Rjbull_: how we do that?
  12. Mindcraftmax59: I've used it in "Randomness, the Game", that's why I was telling you about it
  13. Mindcraftmax59: to have arrays, you want to use "call page" very wisely
  14. Mindcraftmax59: you know that we can program functions thanks to "call page"?
  15. Rjbull_: ohh
  16. Rjbull_: so I can just copy it from your level?
  17. Mindcraftmax59: yes and no. Because it's only an example
  18. Mindcraftmax59: that's why I said there was no inventory there
  19. Mindcraftmax59: I can explain how it works
  20. Mindcraftmax59: so, first, you need to know how to code a function with "call page"
  21. Mindcraftmax59: basically, a function needs inputs, and returns outputs
  22. Mindcraftmax59: it might not need any input, or not return any output though
  23. Mindcraftmax59: and that's usually how most people use "call page"
  24. Mindcraftmax59: but we need to have inputs/outputs for the array
  25. Mindcraftmax59: so to make a function:
  26. Mindcraftmax59: WHEN DO input1 equals value; WHEN DO input2 equals value etc
  27. Mindcraftmax59: WHEN DO "call page" "name of function"
  28. Mindcraftmax59: and in the call page, you have your function
  29. Mindcraftmax59: to get outputs, you put WHEN DO "output1" "equals" "value"; etc
  30. Mindcraftmax59: at the end of the page (or before a "done executing" "call page" that is stopping the page calling)
  31. Mindcraftmax59: have you understood that part?
  32. Mindcraftmax59: so Rj?
  33. Rjbull_: yeh bro!
  34. Rjbull_: thank you so much!
  35. Rjbull_: keep going
  36. Mindcraftmax59: okay, so now for the array implementation
  37. Mindcraftmax59: it will need two types of functions
  38. Mindcraftmax59: one type of functions will set the values in the array
  39. Mindcraftmax59: the other type will get the values from the array
  40. Mindcraftmax59: and you'll have as many functions for both types, as there are slots in the array
  41. Mindcraftmax59: so the first type of functions will be "Set Array1" to "Set Arrayn" where n is the length of the array
  42. Mindcraftmax59: and the other functions will be "Get Array1", "Get Array2" ... "Get Arrayn"
  43. Mindcraftmax59: and remember that these function names are just the names of the pages
  44. Mindcraftmax59: in the page "Get Array1", there will be:
  45. Mindcraftmax59: WHEN "varA" "equals" "varA1"; WHEN DO "varB" "equals" "varB1" etc
  46. Mindcraftmax59: in page "Get Array2":
  47. Mindcraftmax59: WHEN "varA" "equals" "varA2"; WHEN DO "varB" "equals" "varB2" etc
  48. Mindcraftmax59: up to "Get Arrayn"
  49. Mindcraftmax59: so you can just code "Get Array1", and copy paste the page as many time as the length of the array
  50. Mindcraftmax59: and change "varA1", "varB1" etc. to "varAslot_number", "varBslot_number"
  51. Mindcraftmax59: when you call a page "Get Arrayslot_number", it will return the variables "varA", "varB" etc
  52. Mindcraftmax59: now, for "Set Array1":
  53. Mindcraftmax59: WHEN "varA1" "equals" "varA"; WHEN DO "varB1" "equals" "varB1" etc
  54. Mindcraftmax59: yes, it's kind of the opposite of the "Get Array1" code
  55. Mindcraftmax59: so I think you understand what is the code for "Set Array2" etc now
  56. Mindcraftmax59: so, before moving on to third part, actually using these functions like you would with a conventional array
  57. Mindcraftmax59: have you understood that part?
  58. Rjbull_: yeh bro
  59. Rjbull_: thanks so much ahah
  60. Mindcraftmax59: no questions so?
  61. Mindcraftmax59: do you start to get how it works?
  62. Mindcraftmax59: because I might stop here, if you really have understood what I'm doing with that code, you wouldn't even need that third part
  63. Mindcraftmax59: but I'm not going to do that ofc
  64. Mindcraftmax59: so since now, you can get
  65. Mindcraftmax59: "varA" "varB" etc (the returned values)
  66. Mindcraftmax59: you can put code using these variables after calling the pages "Get Arrayslot_number"!
  67. Mindcraftmax59: you only have one code for all the slots in the array
  68. Mindcraftmax59: but how to do that? With a "for each of" loop. And remember how I told you the names of the functions were "Set Arraynumber" and "Get Arraynumber"?
  69. Mindcraftmax59: you can do a "call page" "Set Array" "plus" "number" (same with "Get Array")
  70. Mindcraftmax59: and of course, you can use the current index of a for each of loop
  71. Mindcraftmax59: WHEN "for each of" "length of the array" DO
  72. Mindcraftmax59: (child*1) code for calculating the values of VarA, VarB etc
  73. Mindcraftmax59: (child*1) WHEN DO "call page" "Set Array" "plus" "current index"
  74. Mindcraftmax59: this code was for setting the array
  75. Mindcraftmax59: now for using it:
  76. Mindcraftmax59: WHEN "for each of" "length of the array" DO
  77. Mindcraftmax59: (child*1) WHEN DO "call page" "Get Array" "plus" "current index"
  78. Mindcraftmax59: (child*1) code using the values of VarA, VarB etc
  79. Mindcraftmax59: that's basically it!
  80. Mindcraftmax59: and now, you can look at my level "Randomness, the Game". And go in the logic cube "Polyhedron Brain" (if you don't see the names, go in the pause menu -> Options -> Controls -> Show Object Names On)
  81. Mindcraftmax59: it's an example of the use of this array implementation
  82. Mindcraftmax59: have you got questions?
  83. Mindcraftmax59: do you see how you would use it with the inventory?
  84. Mindcraftmax59: the only part missing from my explanations in order to make an inventory is what is in "(child*1) code for calculating the values of VarA, VarB etc" and "(child*1) code using the values of VarA, VarB etc"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement