I found that when I call isReady(“cleave”) function and my sword supports only “powerup”, I receive an error that I cannot use that. OK.
Is there a way to find what kind of attack my hero can use? So far, I have to change my code but I think there should be a way to write code that will choose correct attack whatever weapon my hero has in his hand.
One solution could be that isReady(“something”) will not return the error but null when my hero cannot use such attack. Or there could be a function that will return list of attacks those are available (similar to the list reported by error message).
Other thing is that cleaveRadius constant is not defined in the game. I noticed that sword description of Long Sword notices cleaveRadius and cleaveDamage constant/variable but I have to use constant 10 in my code.
I have similar problem with glasses. Simple glasses support findNerestEnemy function but advanced glasses doesn’t have this method and it means I have to rewrite my code when I change glases. Maybe this feature is in game by design to force player to rewrite his code but I don’t like it…
Having isReady return false (etc) for invalid options would violate the principal of least astonishment IMO. Sotonin’s code could be a pretty good start on a ‘use my special power’ function, but the times that you want to use powerUp are normally different then the times you would want to use cleave.
Out of curiosity when are you switching back to old glasses?
Out of curiosity when are you switching back to old glasses?
old glases has shorter range, that could be useful; maybe I am wrong and I had to rewrite code to use all possibilities new glasses offer.
Other use is that when I returned to the code that was designed for old glaseeses I had to rewrite code for new glasses, I cannot try old code first because I have the error.
yeah you could just make a function that goes through all the skills you use and sets flags if you have them or not. then use those flags in your code to determine if you can even use the skill or not.
yeah you could just make a function that goes through all the skills you use and sets flags if you have them or not. then use those flags in your code to determine if you can even use the skill or not.
Yes, this is clear, to test at the begining of code what attack can be used and set flags or something like that.
Other option could be a way to find what weapons/items my hero has, to have possibility to get name of weapon, glasses, shield, boots, etc. And have some "small database"in the code with some flags for each supported object.
I agree with PSL, and I make myself the same remark. Why isReady doesn’t just return not ready when attack is not available. When you test different weapons in a level, you have to comment, uncomment code. It could be so simple if isReady worked this way. Maybe the code from sotonin works, but it’s far more complex to use.
For the missing function with more advance items : maybe a way to solve this could be that each level stores the equipment we had the last time we try each level. This way, we will not have to switch manually to old item, or to update our code to retry a level we suceeded.
just my opinion as player.
Good points. isReady and canCast now both just return false if you don’t have the action or spell. I also made it so that if you typo the skill/spell, like self.isReady("cleve"), it’ll throw an error and say, The action is "cleave", not "cleve".