Have you tried single stepping the blocks using the Do It debugging facility?
Also, I noticed that you have not used
- Value procedures
- Procedure parameters
Those could shrink the code for increased clarity.
I found myself lost in your data forest.
Have you tried single stepping the blocks using the Do It debugging facility?
Also, I noticed that you have not used
Those could shrink the code for increased clarity.
I found myself lost in your data forest.
To guard against this type of error, extra checks are needed in the code, for
That extra error checking wrapper is a good place to add Notifiers announcing what assumptions proved wrong in the code.
I did some single stepping with Do It and searching with Ctrl-F in the Blocks Editor.
Battling a ghoul, after confirming a stance:
The error happens when fire effects are calculated.
The fire global is supposed to be a list with at least two items.
Your Battle.Initialize:
Consider adding a comment bubble to the Battle.Initialize even documenting your global variables?
Getting past the wrongly initialize fire and confusion lists, your next error is
It would help knowing how you handle the turn-related lists.
All the turn related lists are reset upon initializing the screen and then they are changed whenever the calculate order procedure is called. Firstly I create the speed_list by adding the speeds of the player and all the enemies.then I make a new list called speed order from sorting that list in order from fastest to slowest (I do this so later when showing the turn order it can recall which speed belongs to which character). Later I create the turns_list. Through some maths it basically makes a list where if a character is n*20 faster than the slowest character then he gets 2^n turns (i.e. if there are 3 characters with speeds 45, 25 and 5,they get 4, 2 and 1 turns respectively) Finally the turn list is created by repeating an algorithm where if a character has more than 1 turn a variable 'next' is calculated by dividing their turn number by that of the next character. If next is other than one, it adds the character index to the turn list 'next' number of times and the next character's index one time before deducting those turns from the turn list and going back and checking again for that charcter if next is other than one. If at any time it isn't then it just adds one turn to the turn order and deducts one from the turns_list. The same happens when it reaches the last character. Then, just for better visuals, I deduct the indices on the turn list by one (so that in the list, for example, 1 represents enemy one) and then convert the 0 to 'Player'. Whenever I tested for the turn order it didn't show any broplems so I don't know what I did in the battle phase so it becomes problematic.
I also forgot to say that I also have a 'turn' list, which I use to see if it's the player's turn and to know which enemy's stats to calculate for their attack. The second index says in which turn we are and goes back to 1 when the turn order is exhausted. The first index is the number/name from the turn_list. I now suspect that the problem is caused by the blocks below, which I use to go to the next turn.
This didn't fix the problem,but it saved future ones,in almost every instance outside of these blocks where I use this list, I had it selecting the item on index 1 when trying to pick the enemy number, when it should have been index 2. I still believe that this is the cause of the problem but I can't find anywhere in the code where a third item is added in the list (the error show a list with three items)
Tl;dr
Can you provide a screenshot of the error?
Is it from @ABG 's screenshot?
If yes, search for replace list item in your blocks
Taifun
The error message is saying that the code tried to replace item 1 of non-list 0 with 0.
This sounds like another mis-dimensioned initialization of a list, like fire and confusion.
Either that or one of the awful default returns
P.S. show us where and how you Initialize global turn_order.
Pps. If you are going to return garbage for not found results, at least return unique garbage to help find the point of failure in the blocks.
I've lost myself in the brambles of this code too many times.
I recommend a controlled burn, and the services of a landscape planner.
Switch to a functional style, and use higher order data structures.
Like I said at the beggining of the post, I just started using app inventor. I have no idea what those things you said are. Should I just look them up and try to implement them or is there a specific block sequence you recommend?
As said before, all the turn related lists and variables (except the turn list from the blocks uploaded before) are in the calculate order procedure, as seen below. Also, the not found results are like that so that there are no errors in this screen if you hadn't visited the other screens before. I guess I can change some of them because of other insurances I put in, but it would be tedious, not really that helpfull since I think the problem is from another source and finally it might create more unforeseen problems in instances of having not visited the previous screens. If it is any help I can upload the .aia file that now contains any changes done since the begining of this post.
There are 11 replace list item blocks. I just made some changes to some of them and I am gonna test them out now, but I doubt that it solved the problem.
Witcher (1).aia (258.0 KB)
This is the updated file and below are the blocks I asked about earlier. Is there a reason the label isn't changed whenever an error happens?
That block only catches component errors, not native block errors.
Read the chapters on lists and procedures in the free book.
Your speed sorting should be applied to a table of (combatant,speed), not just to a list of speeds.
Think of a spreadsheet representing a combat sequence, hit by hit, move by move. What would be in the columns and rows, to show rounds of combat?
I have not seen any posts yet from you showing Do It results. Your blocks should look like a pin cushion with traces
Thanks for all the help but due to my studies I'll probably leave the project for now. When I find more free time again I intend to read these tips and try to continue the project while cleaning up the messy and convoluted parts. If the topic hasn't closed I'll return to post the results or (hopefully not) request more help. Thanks again and sorry if I wasted anyone's time.
This is a good sample project to show off table driven apps.
I started a creature sheet at
to help with land clearing around the combat setup code.
It's just a foundation, though.
Here's another step at whittling away the bloat in this project, by applying reusable code in procedures .
This next step is to load your Bestiary into a TinyDB NameSpace as Creature dictionaries.
Input is the CSV table of the Google Sheet from my prior post:
Creature,Class,TotalPoints,MinSpeed,MaxSpeed,MinStrength,MaxStrength,Image,Description
Ghoul,Necrophage,15,1,13,1,13,ghoul_by_reaper78.jpg,"The ghoul is a necrophage that nests outside cities and villages. They are known to scavenge for dead bodies and mostly cause problems only when near starvation. They also have enough intelligence to hunt near big cities so they can dig up cemeteries or finish off any bodies left by other monsters. They do not seem to have any specific weaknesses, but due to their frail build, they usually don't cause any problem even to the most inexperienced monster hunter."
Nekker,Ogroid,30,15,28,1,28,nekker_by_f1amdring.jpg,Nekkers are extremely common ogroids that mostly hunt as necrophages. Their high speed and tendancy of grouping together is the only saving grace for this mostly weak monster. Due to their existent but not high intelligence they can easily be triicked.
Drowner,Stalker,45,1,43,1,43,drowner_by_gothawolf.jpg,Drowners are stalking necrophages that originate from drowned humans. Despite that they can still reproduce and nest. They are usually found in swamps or beaches eating fish or stalking unfortunate passer-bys. Their aquatic nature makes them slightly weak to fire but they are resiliant enough to attack even when set ablaze.
Wraith,Specter,60,15,58,1,15,wraith_by_vonmquocthai.jpg,"Wraiths are specters of the unavenged. They roam around a place of specific interest to the spirit, like the spot of an improper burial or the scene of a murder. Their curse can be lifted but due to the death of their memories and their relative weakness a monster hunter usually has no physical or moral reason to do so."
Siren,Havrue,75,20,73,1,20,siren_wip_by_davesrightmind.jpg,"Sirens are a type of mermaid that have a unique taste for human flesh. Although they can live off local prey, they often go to human-inhabited beaches and lure unsuspecting victims with their hypnotic songs. They are weak to fire but their high intellect makes them unpredictable."
Werewolf,Cursed,90,30,88,1,30,werewolf_by_llirik_13.jpg,"Werewolves are cursed humans that have taken on the characteristics of wolves. Their high speed , power and animallistic instics make them tough opponents but an experienced witcher hunter should know how to defeat one."
Katakan ,Vampire,105,1,103,1,103,vampire_by_andimayer.jpg,"The Katakan is a form of Vampire that usually lives in isolation. Every so often they will go out to hunt, where they can slaughter dozens of humans to feast on their blood before hybernating. They are methodical attackers that gather their strength before unleashing rapid and strong attacks."
Griffon,Hybrid,120,1,60,1,118,griffin_by_scratcherpen.jpg,"Griffons are a hybrid of a lion and an eagle.These massive hunters usually nest in hills and mountains where they hunt for large livestock. Their bulky hide and massive muscle mass make them herculean obstacles for any monster hunter, but their lack of ground speed and knowledge of combat can be exploited by experienced hunters."
Leshen,Relict,135,1,50,1,50,the_leshen_by_polarwiesel.jpg,Leshens are woodland relicts that live in secluded forests. They mark their territory with shrines and then parasite off of the ecosystem. This unfortunatly leads to humans being cursed and killed by them but their strength means it is more often than not worth it to abandon a village before considering hunting down the monster.
Wyvern,Dragon,150,1,148,1,148,dragons_by_88grzes.jpg,"Wyverns are a rare type of dragon that few have witnessed long enough to specify their appearance and behaviour. It is considered natural that their size, strength, speed and strong scales makes them the apex predators of the land."
This is loaded into a separate TinyDB instance at Screen1 Initialize time on the first run.
I collected the rest of your Screen1 initialization into a separate procedure, to allow deferring its execution until all needed files have been loaded.
An extra attribute ORDER is added to preserve the initial row order from the input CSV text, in case the sort order is important. In the case of your Bestiary, I notice the sort order has the easiest creatures first. Without this ORDER attribute, it would be impossible to guess the original order.