+Dazzatron Posted June 13 Posted June 13 I am using Urwigo and trying to make a cartridge that has All the mascots of past Australian Mega Events scattered across a map of Australia. The idea is to pick them up an place them back it their correct state. once you think they are all in the correct location go to a square outside the country map and it will tell you if you are correct and if you are it will reveal the location of the cache. Everything was working well until I got to over 8 Characters then when I was doing the "On Enter" code for the final square the way I was doing it was with If/Else then contains. Then following with another If/Else then contains. (See image if that doesn't make sense) so I continued on till I was 8 characters in then every time I try and add another If/Else then contains the app crashes. I have 10 characters currently and still need to add at least 2 more real characters and was planing on adding a few fake ones that will need to be put in the "Bin/Trash" as well which I haven't implemented yet. Is there a limit of how many layers deep you can go with the way I am doing it and is there a better way of doing what I am trying to do. I am only new to doing these but am enjoying learning how it all works. These are a few of the ones I created Zantrelli Titan SR-109 Where In The Copper Coast Is Carmen Sandiego 1 Where In The Copper Coast Is Carmen Sandiego 2 Where In The Copper Coast Is Carmen Sandiego 3 All I am sure these could have been done better and easier than the way I did them but had fun doing them. Any way any advice would be great and if there is no way of doing it I will have to change my plan. Quote
+Dazzatron Posted June 13 Author Posted June 13 (edited) I know my map of Australia is off a bit but it is a work in progress I will work on it. Edited June 13 by Dazzatron Quote
Ranger Fox Posted June 14 Posted June 14 I like the map of Australia. That took a lot of work. (Some player apps, though, will instead just simplify it to just a point, so beware.) This is where scripting the cartridge would make things easier. But let's take a look at an option without that. So, let's say we have ten mascots. Instead of making a large if/else statement, set a variable to the number of mascots which must match (all of them). Create a variable that will contain a count of the mascots that do match. You can then have an if statement per mascot, asking if the correct zone contains the correct mascot. If so, increment the correct-matches variable. At the very end, you can test to see if the correct-matches variable equals the total number of mascots variable. In this way, you can easily add and remove mascots from the game without facing a huge if/else statement. You can also have a small series of if/else statements to check against the correct-matches variable to determine the message to show to the player. I'm not sure there is a limit to the number of layers you can go with an if/else statement, but the complexity around maintaining such a structure (especially with a Wherigo builder UI) kicks in at about two levels deep. Just think what it would take for you to remove Fern the Fairy Possum from your current if/else structure. If you instead had something that counted the number of matches, this would be easier. Here's some pseudocode: minimumMatches = 3 correctMatches = 0 if zone1:contains(mascot1) then correctMatches = correctMatches + 1 end if zone2:contains(mascot2) then correctMatches = correctMatches + 1 end if zone3:contains(mascot3) then correctMatches = correctMatches + 1 end playerMessage = "" if correctMatches >= minimumMatches then playerMessage = "You got them all!" --Perhaps do some game-winning stuff here else if correctMatches - 1 >= minimumMatches then playerMessage = "Just one is wrong" else if correctMatches > 0 then playerMessage = "You got some of them right" else playerMessage = "Surprisingly, you got them all wrong" end Wherigo.MessageBox({ Text = playerMessage }) With this type of logic, removing zone2 and mascot2 is easy. Quote
+Dazzatron Posted June 14 Author Posted June 14 I think I can follow that will give it a try and get back to you. Quote
+Dazzatron Posted June 15 Author Posted June 15 At this stage I have a working Wherigo Cartridge I will see if I can add the rest of the Mascots and hopefully it will keep working. Here is what I did to get it working. Wrote some LUA Code and seems to be working. local message = "" if not SA:Contains(Dan) then message = "Not all where they should be Try again" elseif not ACT:Contains(Gangles) then message = "Close but still not right Try again!" elseif not VIC:Contains(Muggle) then message = "I know you at least have a few right but Try again!" elseif not VIC:Contains(Fern) then message = " Try again!" elseif not BIN:Contains(Eddie) then message = " Good try but Try again!" elseif not SA:Contains(Leo) then message = "Getting closer but still not there yet. Try again!" elseif not SA:Contains(Kookie) then message = "Go have another look. Try again!" elseif not QLD:Contains(Cal) then message = "Not quite right. Try again!" elseif not QLD:Contains(Minty) then message = "There is at least 7 Right. Try again!" elseif not QLD:Contains(Spike) then message = "So close but not right. Try again!" elseif not NT:Contains(Bilby) then message = "Give it another look something isn't right. Try again!" else message = "Congratulations! You have placed everyone correctly. The cache is at S XX° XX.XXX E XXX° XX.XXX." end Wherigo.MessageBox{ Text = message } Quote
Ranger Fox Posted June 15 Posted June 15 That's better. It's not difficult to maintain. However, the content of your messages would need to be adjusted if you were to remove a zone in the future. For example, if you were to remove the zone "BIN", you'd have to adjust the message for the zone "QLD" and mascot "Minty" because seven mascots wouldn't be right. Granted, there's little maintenance once a cartridge has been published, so most software engineering maintenance concerns might not apply. However, as one continues to tinker with a cartridge they're creating, it's better to make things easier on yourself. If I was writing the lua script and not using a builder, I would have likely stored objects in a table. Each object would contain a reference to their proper zone and mascot. If I wanted a specific messages based on the number the player has gotten right, I'd have another table for that or just a lookup function. When I evaluate the game-winning condition, I'd just loop through the table that contains the zones and mascots, testing to see if the mascot reference is inside the zone reference. (I have to cut this message short since I need to leave to work church now, but if you're interested in such a lua script, I could type something out for you when I have some time. You don't have to use it, but it might be helpful if you're interested in learning a little more about lua scripting. If you're not, that's fine and it won't hurt any feelings.) Quote
+Dazzatron Posted June 16 Author Posted June 16 I will probably try and redo it at some point closer to what you originally showed me now that I found out what I was doing wrong and that was that I didn't have anything in the Identifier field and I just assumed the Name was enough for the code to know what I was talking about. Which is why after 20+ trys I wasn't getting anywhere with it and abandoned it and tried this way which also didn't work until I worked out about the Identifier field. But Either way thanks for the help I am enjoying learning about how to set these up and getting some good feed back for the ones I have made so planning more in the future. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.