Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Mindcraftmax59: so I was saying that "inventory" is used for simple things
- Rjbull_: ohh
- Mindcraftmax59: once you want to get an inventory with UI, you have to use more complex stuff
- Rjbull_: so... if I want one like minecraft
- Rjbull_: like, boxes at the bottom
- Mindcraftmax59: that one has a fixed number of slots
- Mindcraftmax59: that means that you want an array
- Mindcraftmax59: As I said, there are no native arrays in PS
- Mindcraftmax59: so we have come up with an implementation to fake them
- Mindcraftmax59: (we = I and Arisilde)
- Rjbull_: how we do that?
- Mindcraftmax59: I've used it in "Randomness, the Game", that's why I was telling you about it
- Mindcraftmax59: to have arrays, you want to use "call page" very wisely
- Mindcraftmax59: you know that we can program functions thanks to "call page"?
- Rjbull_: ohh
- Rjbull_: so I can just copy it from your level?
- Mindcraftmax59: yes and no. Because it's only an example
- Mindcraftmax59: that's why I said there was no inventory there
- Mindcraftmax59: I can explain how it works
- Mindcraftmax59: so, first, you need to know how to code a function with "call page"
- Mindcraftmax59: basically, a function needs inputs, and returns outputs
- Mindcraftmax59: it might not need any input, or not return any output though
- Mindcraftmax59: and that's usually how most people use "call page"
- Mindcraftmax59: but we need to have inputs/outputs for the array
- Mindcraftmax59: so to make a function:
- Mindcraftmax59: WHEN DO input1 equals value; WHEN DO input2 equals value etc
- Mindcraftmax59: WHEN DO "call page" "name of function"
- Mindcraftmax59: and in the call page, you have your function
- Mindcraftmax59: to get outputs, you put WHEN DO "output1" "equals" "value"; etc
- Mindcraftmax59: at the end of the page (or before a "done executing" "call page" that is stopping the page calling)
- Mindcraftmax59: have you understood that part?
- Mindcraftmax59: so Rj?
- Rjbull_: yeh bro!
- Rjbull_: thank you so much!
- Rjbull_: keep going
- Mindcraftmax59: okay, so now for the array implementation
- Mindcraftmax59: it will need two types of functions
- Mindcraftmax59: one type of functions will set the values in the array
- Mindcraftmax59: the other type will get the values from the array
- Mindcraftmax59: and you'll have as many functions for both types, as there are slots in the array
- Mindcraftmax59: so the first type of functions will be "Set Array1" to "Set Arrayn" where n is the length of the array
- Mindcraftmax59: and the other functions will be "Get Array1", "Get Array2" ... "Get Arrayn"
- Mindcraftmax59: and remember that these function names are just the names of the pages
- Mindcraftmax59: in the page "Get Array1", there will be:
- Mindcraftmax59: WHEN "varA" "equals" "varA1"; WHEN DO "varB" "equals" "varB1" etc
- Mindcraftmax59: in page "Get Array2":
- Mindcraftmax59: WHEN "varA" "equals" "varA2"; WHEN DO "varB" "equals" "varB2" etc
- Mindcraftmax59: up to "Get Arrayn"
- Mindcraftmax59: so you can just code "Get Array1", and copy paste the page as many time as the length of the array
- Mindcraftmax59: and change "varA1", "varB1" etc. to "varAslot_number", "varBslot_number"
- Mindcraftmax59: when you call a page "Get Arrayslot_number", it will return the variables "varA", "varB" etc
- Mindcraftmax59: now, for "Set Array1":
- Mindcraftmax59: WHEN "varA1" "equals" "varA"; WHEN DO "varB1" "equals" "varB1" etc
- Mindcraftmax59: yes, it's kind of the opposite of the "Get Array1" code
- Mindcraftmax59: so I think you understand what is the code for "Set Array2" etc now
- Mindcraftmax59: so, before moving on to third part, actually using these functions like you would with a conventional array
- Mindcraftmax59: have you understood that part?
- Rjbull_: yeh bro
- Rjbull_: thanks so much ahah
- Mindcraftmax59: no questions so?
- Mindcraftmax59: do you start to get how it works?
- 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
- Mindcraftmax59: but I'm not going to do that ofc
- Mindcraftmax59: so since now, you can get
- Mindcraftmax59: "varA" "varB" etc (the returned values)
- Mindcraftmax59: you can put code using these variables after calling the pages "Get Arrayslot_number"!
- Mindcraftmax59: you only have one code for all the slots in the array
- 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"?
- Mindcraftmax59: you can do a "call page" "Set Array" "plus" "number" (same with "Get Array")
- Mindcraftmax59: and of course, you can use the current index of a for each of loop
- Mindcraftmax59: WHEN "for each of" "length of the array" DO
- Mindcraftmax59: (child*1) code for calculating the values of VarA, VarB etc
- Mindcraftmax59: (child*1) WHEN DO "call page" "Set Array" "plus" "current index"
- Mindcraftmax59: this code was for setting the array
- Mindcraftmax59: now for using it:
- Mindcraftmax59: WHEN "for each of" "length of the array" DO
- Mindcraftmax59: (child*1) WHEN DO "call page" "Get Array" "plus" "current index"
- Mindcraftmax59: (child*1) code using the values of VarA, VarB etc
- Mindcraftmax59: that's basically it!
- 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)
- Mindcraftmax59: it's an example of the use of this array implementation
- Mindcraftmax59: have you got questions?
- Mindcraftmax59: do you see how you would use it with the inventory?
- 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