+HwyGuy Posted November 4, 2022 Share Posted November 4, 2022 For several months, off and on, I have been attempting to write a cartridge in Earwigo, where the player attempts to find a number of items to be scattered in a number of zones. A modified Clue scenario if you will. I have read the posts here and have Googled Lua commands and I fear I am more confused than when I started. I did look at Battleships and Wack a Lackey but whatever I attempted from those was lost in the differences. I have tried various iterations of all the questions below and can never get it past the emulator. If I take out ALL mentions of tables etc then I can enter the first zone after start and have some things work but not what I want. I have been attempting to populate the tables on exit from the Start zone and putting the various functions etc in the Author Script tab in the Cartridge tab. I have attempted to populate a table a couple of different ways and each time the emulator finds a ") expected near a ," error or some variation. I plan to remove one of the items in the table and have Gallagher smash it with the sledgehammer. BUT that is another days frustration.. table = {'Apple', 'Banana', 'Orange', 'Watermelon' , 'tomato'} or a series of: table.insert(entry, "apple") then table.insert(entry, "banana") etc ... Neither way got past the Emulator. Should I be attempting to use an array instead of a table? Adding a whole lot more headaches. What I have not seen in any of the posts is a complete "idiots" list of parameters. If an entry is : table = {'Apple', 'Banana', 'Orange', 'Watermelon' , 'tomato'} does table require a var_ prefix? ==> var_table or is it tabentry ?? IS table a variable with a "string" designation? ARE apple, banana etc Items? Do they need to be identified as itemApple, itemOrange etc when putting them in the table? DO you need a Require "table" line at the start of the Author Script the same as Require "math"? In one of the posts it gave wonderful examples of coding to manipulate data from the tables using Random. Great except - does word Random have to appear in the statement? The example I am asking about was: tabRandom = RandomObjects({itemHammer, itemNail, itemRope, itemKnife}) many of my questions are a direct result of this example. entry = tabRandom:GetNext() where in this example is the Random generator - I am assuming RandomObjects but can I change the Objects part to something I wish to use like "squished" or would that be to the left of the equal and be tabSquished ? I also want to follow up this table with another of the implements used to smash them - hammer, mallet, bat etc. So the next table would be TabSmasher = RandomObjects ((itemhammer, itemmallet, itembat, itemsmashomatic))?? Would there be a conflict with the 2 RandomObjects parts? Thanks for looking at this and I hope it makes sense and the frustration hasn't totally made it that I missed a simple vital step that anyone should have seen. HwyGuy Quote Link to comment
+Hügh Posted November 5, 2022 Share Posted November 5, 2022 (edited) 17 hours ago, HwyGuy said: Should I be attempting to use an array instead of a table? In Lua, all arrays are tables. An array is simply a table whose keys are sequential integers. 17 hours ago, HwyGuy said: If an entry is : table = {'Apple', 'Banana', 'Orange', 'Watermelon' , 'tomato'} does table require a var_ prefix? ==> var_table or is it tabentry ?? In general, variables in Lua do not require any form of prefix. You simply put the name of the variable on the left, and the value you are assigning on the right. You later refer to these values by their name. a = 1 b = 2 print(a + b) -- 3 print(10*a + b) -- 12 By enclosing a value in quotes, you get a string. greeting = "hello" hello = "HwyGuy" Note here that "greeting" is a variable containing "hello" and "hello" is a variable containing "HwyGuy". They are completely separate and do not interact with each other. The builder simply inserts the "var_" prefix to prevent any name collisions. 17 hours ago, HwyGuy said: IS table a variable with a "string" designation? Not sure what you mean. 17 hours ago, HwyGuy said: ARE apple, banana etc Items? Do they need to be identified as itemApple, itemOrange etc when putting them in the table? As above, by putting quotes around the fruits, you make them literal strings. To refer to the variable, you need to use the name of the variable. Likely you want itemApple since as before the builder is probably inserting the item prefix. For instance, itemApple = "This is an Apple." orange = "This is an Orange." banana = "This is a Banana." fruits = { itemApple, orange, "banana" } print(fruits[1]) -- This is an Apple. print(fruits[2]) -- This is an Orange. print(fruits[3]) -- banana 17 hours ago, HwyGuy said: DO you need a Require "table" line at the start of the Author Script the same as Require "math"? I do not believe so. 17 hours ago, HwyGuy said: Great except - does word Random have to appear in the statement? The example I am asking about was: tabRandom = RandomObjects({itemHammer, itemNail, itemRope, itemKnife}) many of my questions are a direct result of this example. entry = tabRandom:GetNext() where in this example is the Random generator - I am assuming RandomObjects but can I change the Objects part to something I wish to use like "squished" or would that be to the left of the equal and be tabSquished ? You seem confused. "RandomObjects" is a function defined elsewhere. It accepts, as an argument, an array (a table) with a number of items, and returns a "generator" that picks random items from the array you supplied it with. "RandomObjects" is absolutely necessary, since that is the name of the function. However you can change the name of the variable you are assigning to. randomNumberGenerator = RandomObjects({ 1, 2, 17, 4, 5 }) firstRandomNumber = randomNumberGenerator:GetNext() -- either 1, 2, 17, 4, or 5 secondRandomNumber = randomNumberGenerator:GetNext() -- either 1, 2, 17, 4, or 5 thirdRandomNumber = randomNumberGenerator:GetNext() -- either 1, 2, 17, 4, or 5 fourthRandomNumber = randomNumberGenerator:GetNext() -- either 1, 2, 17, 4, or 5 -- and so on. 17 hours ago, HwyGuy said: Would there be a conflict with the 2 RandomObjects parts? No. "RandomObjects" is a function, and you're simply referring to it twice. -- square: Calculate the square of a number. function square(x) return x * x end a = square(5) -- 25 b = square(6) -- 36 c = square(-5) -- 25 Edited November 5, 2022 by Hügh 1 Quote Link to comment
+HwyGuy Posted November 9, 2022 Author Share Posted November 9, 2022 OK - have had a chance to look this over after a death in the family sidetracked me for a bit, I understand most of what you placed in your answer - thank you for that. I have tried most of it and always run into the Emulator tossing it back at me, which is why I sent the first post. So what I did was write three parts in a function in Author Script section and run one part at a time 1 assign values to two variables and attempt to print them the variables were assigned to be numbers 2 assign alpha characters to two variables and try to print them - the variable were assigned to be strings 3 assign alpha characters to three variables then put them in a table and then try to print the variables. - the variables were assigned to be strings What I got were error messages in the Emulator for each of them. 1 ERROR cartridge.lua:560: '(' expected near 'arrow' 2 ERROR cartridge.lua:570: '(' expected near 'Greeting' 3 ERROR cartridge.lua:592: '(' expected near 'itemApple' Pretty much what I have been running into each and every attempt at any of those actions for the last months. So - still confused Here is the Author Script where I inserted the --- in front of the 2 sections I did not want to run on each of the 3 attempts. function TryforTable --- 1 --- arrow = 2 --- bow = 3 --- Print (arrow + bow) --- Print (10*arrow + bow) --- 2 --- Greeting = "hello" --- Hello = "HwyGuy" --- Print (greeting hello) --- 3 itemApple = "This is an Apple." Lime = "This is an Lime." banana = "This is a Banana." fruits = { itemApple, Lime, "banana" } print(fruits[1]) -- This is an Apple. print(fruits[2]) -- This is an Orange. print(fruits[3]) -- banana end The Author Script did not turn the "banana" in the third section a nice black colour after I cut/pasted it in but I attempted to run it anyway, as I couldn't figure how to change the formatting to get the output expected . Any thought on where I am on the wrong track and how to get back on the rails?? Thanks HwyGuy Quote Link to comment
+IvoReikTeoViel Posted November 9, 2022 Share Posted November 9, 2022 11 hours ago, HwyGuy said: function TryforTable --- 1 --- arrow = 2 --- bow = 3 --- Print (arrow + bow) --- Print (10*arrow + bow) If this is exactly what you wrote, you should be aware that the Lua language is case sensitive. That is - the word "print" is a predefined command, whereas the word "Print" might be a variable you set. I put your text into the author section in Earwigo and got no errors in the Webwigo player after minor changes: --1 arrow = 2 bow = 3 print (arrow + bow) print (10*arrow + bow) --2 Greeting = "hello" Hello = "HwyGuy" print (Greeting , Hello) -- (inserted ' , ´ between the variables) --3 itemApple = "This is an Apple." Lime = "This is a Lime." banana = "This is a Banana." fruits = {itemApple, Lime, "banana"} print(fruits[1]) -- This is an Apple. print(fruits[2]) -- This is an Orange. print(fruits[3]) -- banana The result in Lua console is: 5 23 hello HwyGuy This is an Apple. This is a Lime. banana On 11/4/2022 at 11:47 PM, HwyGuy said: IS table a variable with a "string" designation? I would say that a table may consist of, or contain, several variables. Those variables can be both string variables, integer variables and "flags" (value true or false), also inside the same table. Quote Link to comment
+HwyGuy Posted November 9, 2022 Author Share Posted November 9, 2022 Case sensitive - yes - that could easily be my problem. I must admit I had paid just about no attention to case. Is there a listing of the predefined commands somewhere? That might help with further problems before they start.. Thanks for your time spent in getting me going in the right direction. HwyGuy Quote Link to comment
+IvoReikTeoViel Posted November 9, 2022 Share Posted November 9, 2022 I'm rather new to this myself. As far as I know, by reading a lot of older posts in this forum, there is never made any official Wherigo Builder Reference Guide. People have gained knowledge through example cartridges, learning by doing and sharing of failures and successes. The closest I have come to a reference guide for the specific Wherigo commands/functions, are these two links: https://jakuje.dta3.com/webwig/luadoc/index.html http://wiki.wherigofoundation.com/index.php?title=Wherigo_(Class) In addition, I have searched a bit in the Lua 5.1 Reference Guide http://www.lua.org/manual/5.1/manual.html and looked in a Lua tutorial https://www.tutorialspoint.com/lua for some basic examples to get a better understanding of some of the most used commands. The Earwigo-wiki http://www.earwigo.net/WWB/wiki/doku.php gave a kick-start to the basic principles of building a Wherigo cartridge and an introduction to this specific builder. I guess you have already seen this site as it is closely linked to the builder. Beside this Wherigo forum there has also been a forum for Earwigo users, but I haven't got any response to my request for membership. Does anyone know if that forum is still active/available? Quote Link to comment
+HwyGuy Posted November 10, 2022 Author Share Posted November 10, 2022 The Earwigo - WWB - the Wherigo™ Web Builder forum on Google Groups has had only 2 topics this year, the last being Feb 11. So - not so much. Quote Link to comment
+Hügh Posted November 10, 2022 Share Posted November 10, 2022 3 hours ago, IvoReikTeoViel said: Beside this Wherigo forum there has also been a forum for Earwigo users, but I haven't got any response to my request for membership. Have you emailed sTeamTraen directly? Quote Link to comment
Ranger Fox Posted November 10, 2022 Share Posted November 10, 2022 I've made extensive use of tables in my Cacher Pursuit cartridge. Look in its Init() function to see if that's of help to you. I have a table called allQuestionGroups in which I store a question group, which is a table itself of a table of objects (objects are nothing more than tables themselves). The last I knew, this cartridge compiled and worked in emulators and player apps. You can download the source code and look through it. The source is clean, hand-created, and practically everything is commented (because it's meant for people to learn from). All but one of my cartridges, Tetris, is open source. An excerpt from the cartridge, commented for this thread: --Defining a new table local allQuestionGroups = {} --Defining a question group table local qgroup = nil --Creating a question group table like an anonymous type. Note I'm also setting up a table called Questions inside. qgroup = { Zone = zoneCachingTerms, Category = "Caching Terms", Questions = {}, MaxAttempts = 5, Complete = not zoneCachingTerms.Active, WedgeMedia=zmediaWedge1, SuccessMessage = "Great! You earned a pie wedge!", IncorrectMessage = "That's incorrect. Try another question.", GameOverMessage = "Guess you need to get out a dictionary. Game Over.", GameOverMedia = zmediaGameOver } --Inserting the question group table into the main table that stores all question groups table.insert(allQuestionGroups, qgroup) --Creating a table like an anonymous type to insert into my question group table table.insert(qgroup.Questions, { Type = "MC", IsAsked = false, Question = "What event is normally held in April?", Options = { "CITO", "Geowoodstock", "Geobash"}, Answers = {"CITO"}, Media = nil }) --And again table.insert(qgroup.Questions, { Type = "OA", IsAsked = false, Question = "The geodetic discs fall under what category?", Answers = {"Benchmark", "Benchmarks"}, Media = nil }) In pseudocode, the structure would equate to this (omitting a few properties for brevity): List<QuestionGroup> allQuestionGroups; class QuestionGroup { List<Question> Questions; Zone Zone; string Category; int MaxAttempts; bool Complete; } class Question { string Type; bool IsAsked; string Question; } Quote Link to comment
+IvoReikTeoViel Posted November 10, 2022 Share Posted November 10, 2022 17 hours ago, Hügh said: Have you emailed sTeamTraen directly? Thank you both for responding about the Earwigo group. Before answering "yes, of course I've emailed him" I double checked that it was really sent, not just put into a draft, early August. BUT.. for some unknown reason, I managed to left out a single letter from his address. Usually Google gives me a feedback when there is no receiver of my emails, but not this time.. I think the lesson I learned about precise spelling fits well inside this thread after my commenting on case sensitivity Quote Link to comment
+HwyGuy Posted November 14, 2022 Author Share Posted November 14, 2022 I downloaded the Cache Pursuit cartridge and have tried to understand the "makeup" of the table. The ones you used are like Ferrari's and I wish to make a model T table. I want to be able to enter 3 separate groups of 4 or 5 items into (for ease of keeping track in my mind) 3 separate tables, then randomly remove one item from each of the 3 tables, and then randomly show the players one of the remaining 3 or 4 items from two of the 3 tables when they enter a zone. Confused yet? From Cache Pursuit, the first table would be qgroup, I will use one of my own eg. Stones The 5 original items would be then inserted into a table with a "table.insert" - I would then come up with 2 more table names for the other 2. eg. Table ==> Stones Items ===> Mick, Charlie, Keith, Bill, Brian Second Table ===> Beach Items ==> Carl, Al, Brian etc. The items would be removed from each of the tables with a tabInitial = RandomObjects(Stones) command and then an "entry = tabInitial:GetNextWithRemove()" - this wasn't in Cache Pursuit but I saw it on another forum post. When I want to show an item to the player I can pick it with a "tabRandom:GetNext()' - again another farum post Any time I have attempted this - I get bogged down in errors in Emulator. It doesn't like the RandomObjects command - always looking for things inside a " or near a ) or...... I realize that I could follow the Cache Pursuit idea of the 3 tables inside a larger table. I would assume that instead of one item being inserted into a table, you would have to insert two - a category and an item eg. Stones, Keith Stones,Mick etc others Beach, Dennis Beach, Carl etc to keep the items able to be accessed separately. Where this falls apart for me is that I get totally flummoxed after staring at the Cache Pursuit, I have no idea how to remove just the item from the 2 item line in the table eg Charlie I don't think that in my model T idea I have the size concerns like in the Cache Pursuit so the 3 separate tables works for me. Am I close to the correct idea? Any ideas of why RandomObjects causes so much angst? One note: I downloaded Cache Pursuit, installed it into Earwigo and attempted to run it in Emulator to see it work - Emulator crashed - looking for something near a ) = Figures!! Thanks again for your help but this is getting to be a pain lol HwyGuy Quote Link to comment
Ranger Fox Posted November 17, 2022 Share Posted November 17, 2022 Let's see if I have this right: you have some tables. You would like to remove a random item from each table, then you would like to show a random item from each table. I created this demo cartridge (hosted on my NAS). It contains one zone. When you start the cartridge, it will populate three tables (I'm not doing anything with the third). When you enter the only zone, a random value will be removed from two tables, a random value will be chosen among the items that remain in those two tables, and a message box will be shown with the results from the first table's operation. Dismissing the first message box will show a message box with the results from the second table's operation. Quote Link to comment
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.