learn-gdscript
learn-gdscript copied to clipboard
lesson 23 practice " Using right items" task is a unclear and may be teaching bad habits or hardcoding values
I have a programming background so my immediate thought was that loops and conditional checking was what the problem was looking for, especially since the lesson module discusses use of the size() method. Something to the effect of
loop over inventory:
find the first sword in the inventory array
use it
loop over inventory:
to find the first shield in the inventory array
use it
I wrote this solution assuming the inventory array contained strings, as shown in the associated lesson module, and was surprised to find this was not the case; string matching failed, inventory wasn't really accessible, print functions (e.g., print(inventory.size()) didn't work like in the lesson) and my solution was just super broken. I then realized this was maybe over-engineered and tried the much simpler answer of human visual inspection of the inventory array image on the right and gave a hard-coded answer of use_item(inventory[x]) use_item(inventory[y]) and it worked. This feels wrong from a teaching perspective.
As a long time programmer and teacher, this lesson/practice really bothered me because it teaches a bad habit of hardcoding magic values specific to the example and doesn't teach anything about the dynamic nature of data which is a core concept. I feel like a much better lesson would include more boilerplate code to scan the inventory array, as described above in the pseudocode, and have the student flesh it out the rest of the way to make it functional in a more general purpose way (and teach better habits that more closely reflect real-world use cases). Maybe even just provide the full answer for finding the first sword and leave the student to copy it for finding the shield. Also maybe consider renaming the function pick_sword_and_shield() to be specific to the above pseudocode if making these changes.
Thank you for the feedback. In general, we are well aware of limits of the app and the series, and to me, it could use a holistic content pass to flesh everything out or even a remake to unlock some technological limitations. I'd like to go through everything and flesh it out more. But we have to focus on our school curriculum.
I think your issue, while I agree it would be something worth introducing, is something beyond the scope of this lesson, whose goal is just introducing how to access elements in an array by index. The lesson could be modified to make this more explicit.
I thought we reused the inventory example after this lesson closer to what you suggest, with dictionaries, but I'll have to check again.
I also found it unclear how to complete this task. I believe my issue is because the inventory array shown in the code was empty, and it didn't make much sense to iterate over or index into an empty array. I thought I might have to populate the array with something, but I couldn't figure out how to make that make sense.
The starting code:
var inventory = []
func pick_items():
It turns out that this array is actually populated with items, so I tried approaching the problem the same way as @jman904 and ran into the same issues. I had to look at the suggested solution to figure out what I was supposed to do for this problem, and that it expected me to just hard-code inventory indexes of the items I wanted to use.
I think if the inventory was declared as var inventory = ["gems", "sword", "shield", ....], or something similar, it would be a bit more intuitive how you're supposed to solve the problem.
Just coming on here to add my 2 cents to the pile - as a programmer with a pretty good grasp of other languages, the intention of this question confused the hell outta' me. It wasn't very clear from the question that you're supposed to actually look at the output window to use the items, and that the specific task is to 'equip a sword' and 'equip a shield'.
As @waptang suggested, I'd also say that the inventory array shoud be pre-filled with all 12 items in the answer area, so it's clear that you have to manually access the inventory using an array index.
Thanks for the feedback everyone. My plate's really full so I'm not finding time to make improvements to the app but it sounds good.
I agreed with some of the points in this issue, so I decided to poke into the repo and see if I could help.
I had a look through the code and noticed that the Inventory is being randomly generated, then items 6 and 8 are being made into "sword" and "shield" just to guarantee that there's at least one of each.
The "starting code" in the lesson.tres has the empty inventory array, but it looks like you can't access the randomly generated container from there.
One option could be to hardcode the contents of the container (because it doesn't really need to be randomised) and then put the matching contents in the starting code. It feels a bit dirty to do this, but it would at least mean that the code for the inventory matches the GUI so people can see that both are the same array.
Another suggestion to mitigate the cognitive dissonance is to rewrite the task itself to imply selection of individual items rather than searching (looping) through the array. Here's a suggestion:
In our game, the player has an inventory that works as an array under the hood. They know that they have a sword and a shield somewhere in their inventory but they don't remember exactly where. You can see the inventory on the right as well as the indexes for each item. Find one sword and one shield and call use_item() on them, then the player will be able to equip those items. For example, you can use the first item by calling use_item(inventory[0])."
I'm not sure if it would help to also include a documentation section for use_item() ?
@Marcchee First of all, thanks much for taking the time to help! Hard-coding the inventory content in the exercise (and possibly under the hood in the practice test code) sounds great, and your writeup looks good too.
If you do add the inventory content in the var inventory displayed to the user, there should be probably an extra test to ensure that students don't modify it, because they tend to do that quite a bit (that's why the app doesn't show much code, we didn't have the bandwidth to implement a read-only display for parts of the code we'd want to show initially).
Your suggestion is good, I'd add a little more and write it like this for a little extra clarity (the little extra repetition can help beginners and younger students):
In our game, the player has an inventory that works as an array under the hood. The player knows they have a sword and a shield somewhere in their inventory, but they don't remember exactly where. You can see the inventory drawn on the right, along with the index of each item in the inventory. Your task is find one sword and one shield in the array, then call use_item() on each of them so the player can equip those items. For example, if the first item in the array is what you need, you would call
use_item(inventory[0]).
If you need any info on the codebase, don't hesitate to ping me.
Awesome! I'm still quite new to Godot, so I'll have to figure out how to actually build and test the tutorials and then I'll be ready to make some changes to help!