That is the image of my arrow code. It detects when the arrow hits a wall, and then checks the state of the sword that is supposed to be blocking the arrow. The first detection is whether the sword is resting or attacking, and that part works fine. But the next part, where it is supposed to detect whether the sword is up, does not work. Even if my sword is in the up position, when that arrow hits the wall, it does damage anyway.
The weird part is that
a. The sword moves up and down like it is supposed to, so obviously the swordState is working.
b. All other positions work. Down and forward block like they are supposed to. I can find no reason that those if loops do not work.
c. I have 6 arrows, and the up is broken for all 6 of them.
Could someone please help or at least explain what the problem is?
Something is probably not correct in your code here
This code only executes when the Arrow Y coordinate is exactly 40 . Perhaps try >= 40 ?
Debugging code that depends on Procedures that are unexplained or without checking on a device are extremely difficult to detect and fix. You haven’t provided all your Blocks or an aia so I offer you http://ai2.appinventor.mit.edu/reference/other/testing.html that jprovides advice that should help you debug this.
I would start exploring by Disabling all the blocks below the up state scenario. Then make sure your code for up works. Then get the other parts of your interesting game to work.
The arrow can only be 40, 117, or 183 (up, middle, or down positions). All other code, like ALL of it, works. The only thing that doesn’t is that pesky up block in all 6 arrows. Since I copied and pasted, the problem is probably the same in all of them.
Regarding your solution, I tried disabling the other blocks, which just breaks the game even more, since now the arrows are completely unblockable. Let me send you an image of all of my code…
And finally here is the project aia. FINAL_PROJECT.aia (227.4 KB)
If you could take a look at that, since you obviously have more experience then I do.
Personally I learned programming through some OOP Python and basic js.
I tried to self debug, but I couldn’t find any difference between that up state thing and the others.
Help would be much appreciated!
Ok. I don’t have a fix. I can tell you these are current issues:
How it works.
the sword position buttons do not work at all with the code you provided.
you use a different ImageSprite for each sword position. You shouldn’t do that I expect. Instead use a single ImageSprite for swordPosition and use the upButton, ForwardButton and DownButton to change the swordPosition image. That could work to block arrows but it won’t. here is why:
Although an image has a transparent background, the ‘collision’ takes place at the image outline, not at the visible part of the image.
You are attempting to ’ block arrows’ using your swordUpdate Clock with a 75 ms interval… will never work with AI2’s graphics. A single blink is … The duration of an eye blink is on average 100–150 milliseconds
Your images for the swords are 277x185 pixels but you display a sword up at 100x120 pixels. this is not a killer issue but when you depend on the cpu to shrink the image at fast speeds, you are stressing the Android’s resources.
I would provide more information but I cannot get
Your arrows work beautifully!
I got the sword movement buttons to ‘work’ (kind of) by adding the circled block
This kind of app benefits from use of generic (Any Sprite) blocks to eliminate
lots of duplication, so you only have to fix things in one place vs 6 places.
If you keep a global list of your Arrow Component blocks,
you can reuse code by arrow number procedure parameters.
Likewise for your three sword sprites, you can keep them in a list to test if the other
sprite in an arrow collision is a sword (in the list of sword components) versus the knight (ouch).
It is not a final exam project, sorry for the misleading name.
It is called that because it is an amalgamation of previous projects where I tested separate components of that.
Thanks for the helpful tips, I’ll try working on it tomorrow with what you guys have said.
Steve, the arrows trigger collisions when they hit this sprite called sword wall, which is in front of the swords. Maybe the sword points out in front of it. Actually I’ll look into that… but I don’t have time today
Thanks for the explanation. 'Maybe the sword points out in front of it.' ... it sure looks like that is true. For testing, you might want to set a picture to it (to make it 'visible' while testing). This might work
Arrows
Image shows arrow outline of 361x127 pixels in red that you display at 100x50. Crop your arrows to the green outline in your Media?
Steve, what do you mean the sword buttons don’t work at all?
I tried them using my Acer tablet and the sword moves fine…
There is something I don’t understand. The lower sword, as you can tell, is much bigger. Yet it shows as the same size when I test the app?
[Edit] - I just cropped the arrow
[Edit 2] The reason the arrow is facing the opposite way is because of ai2’s heading thing. To make things go left, apparently the heading has to be 180, so my image is basically flipped. Is there a fix for this?
[Edit 3, sorry] Oh, and regarding tablet sizes, it looks messed up in the editor, but it works on phones and tablets for some strange reason. The tablet I use… I don’t know exactly what model, but it is similar in size to iPad mini 4 I guess, and it fits very snugly.
[Edit 4, really sorry] I have a question regarding the sword sticking out. When the arrow collides with that, will it do anything or just keep moving, since I have no code telling it what to do when that happens?
what do you mean the sword buttons don’t work at all? Just what I said, when running the app using the companion on my Android 8.1 tablet, the buttons did not ‘move’ the sword. I added the call updateSword block in the event handlers following the swordState as I posted earlier and the sword display seem to change appropriately. Why they do not work without the additional block on my table but work on your Acer, I do not know.
The lower sword, as you can tell, is much bigger. Yet it shows as the same size when I test the app. Probably because you force the image to the size in your other blocks . the image I showed is how it displays in the Designer.
Arrows cropped Actually not; this is your cropped arrow
The image is huge 687x135 pixels; not what you want. …and your image should be within the red boundaries; as it is the entire image dimensions are the arrow plus the purple. Try again?
sticking out … well if the outline of the sword extends beyond the barrier (to the right) the arrow
will collide with that sword. That is what happens when you use the CollisionWith blocks …it
executes whenever it encounters any sprite. facing opposite direction you can handle that by using Paint or other software to make an
additional arrow png (arrowPointedLeft.png) or using the arrow sprite heading and set it to 180
similarly, you could use only one sword sprite. How, use the single image and use the heading property to position the sword instead of multiple images.