Jump to content

Tables using Earwigo


HwyGuy

Recommended Posts

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

 

Link to comment
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 by Hügh
  • Helpful 1
Link to comment

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.

ERROR

cartridge.lua:560: '(' expected near 'arrow'

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

 

Link to comment
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.

Link to comment

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

Link to comment

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?

Link to comment

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;
}

 

Link to comment
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 ;)

Link to comment

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

 

 

 

Link to comment

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.

Link to comment

I spent some time looking at your Fun with Tables cartridge and then ran smack into the Emulator not liking the MessageBox output.   Before I managed to make any headway on it - real life intruded.    I now find myself relooking at the demo.    Again I can't get anything past the Emulator.   I keep getting errors like "unexpected symbol"  near a } "  or a couple of others.

 

I have tried changing the " to [[ as I have seen in other examples,  changing the ' to " ,  changing STONES to Stones,  adding local in front of stonesRemoved,  took out the #tbl output.   Managed to get exactly - Nowhere!  

 

Frustration is rearing its ugly head - as it did a year ago.

 

One time I got output that was the first 2 words - "Stones removed"   but no variables.  That was so many attempts back I couldn't find what I did with a telescope.  It was the only time it worked.   

 

SO - I figure I know its me.      I have just been using what was currently in the Fun with Tables cartridge.   I did rename it to demo and changed the name in the function statement.   

 

Do  any of the variables, need to be  defined in the Variables tab in the main part of Earwigo? 

I am unsure of what needs to be in a MessageBox statement - such as what is the CallBack?

Can I write these MessageBox statements in the main part in the Messages tab?     I didn't think you can access variables inside the Author Script from the main part.

Are those "." between each part of the MessageBox statement or are they ","  ?   I think I have seen both and I have seen  "~~"  as well.   Tried them all.

 

I have been unable to find an example of the way that the message was constructed in the Fun with Tables cartridge with the use of :

 

       local stonesmessage = {blah blah} and then  Wherigo.MessageBox{Text= stonesMessage, Callback = function() .........   

 

I have found lots with just the Wherigo.MessageBox statements so I am unsure of what I should be seeing in this paticular example.

 

At this point I am at a loss for which way to turn now.    

 

Thanks again for getting this far in my confusion

HwyGuy

 

 

Link to comment

The variables don't need to be defined in the variables tab because they're tables, and as such I haven't had much success in persisting these across cartridge restores, likely because the Wherigo variables were supposed to use primitive types.  (Admittedly, I didn't spend quality time looking into it, and this was back when I was creating the Battleship cartridge several years ago.)

 

The callback in a MessageBox statement is typically a function name to call after the user dismisses the message box.  In my example, I wanted to use the variable beachMessage in my second message box, so I defined an anonymous function inline with my callback.  Doing so allowed me to access the variable within that function call.  The programming term for this is "closure".

 

I am unfamiliar with accessing author script variables inside an Earwigo message.  You might be able to write the following and it work out:

         Your HP is ]] .. playerHp .. [[.  Your MP is ]] .. playerMp .. [[

This is assuming all Earwigo does is encase your message in double square brackets.

 

I should note you can use either double quotes or double square brackets to denote text with message boxes.  Since I primarily use C# and JavaScript, I tend to use double quotes in my examples.

 

In what you wrote, you typed the variable name "stonesmessage" and you were trying to use the variable name "stonesMessage" in the message box.  These are not the same.  You'll need to pay attention to the casing you're using.  Perhaps that might be contributing to your troubles.

 

If you want to share more of your cartridge's code, I could help a little more.  Just please be patient with me.  October is my busiest month because I photograph haunted attractions (as SeeYouScream) and autumn foliage on top of the extra hours I work at my job.

Link to comment

Thank you for putting up with this continuing saga.

 

I checked - I had used the stonesMessage in the coding - just not the forum.

 

I have removed the extra 2 tables to try and "dumb it down" for me but I am still having the same problems getting it past the Emulator.

 

I have tried every variation of the message that I can think of and I get some form of this message from the Emulator each time: image.png.e3245e454ff39846100202c9161c45ad.png

 

 

My current lines 340 to 344 are:

 


    local stonesMessage = {"STONES: Removed:  "  .. removedStones ..  ", Chosen: " .. stonesItem ..  "Entries left: "  .. #stonesTable    }
  
    Wherigo.MessageBox{Text=stonesMessage, Callback=function() 
    
    }

  end

 

I have tried double brackets, putting the message inside the MessageBox, added local to the 2 variables, etc.   The only thing I wonder about is in the setup of the cartridge - the boxes where the properties of the variables are assigned - my boxes are blank - no ~var or .. .   Would this be a cause?

 

I believe I have everything typed the same as your demo cartridge in the rest of the Author Script.   If I knew how I would include the cartridge.

 

Take your time to peruse this - it has become more of a white whale than a viable cache option at this point as I still am unclear of how much info from  the Author Script is readily available to use in the main body of the cartridge.  Ex. would  the variable "removedstones" be able to be placed in inventory? etc.

 

 

Thanks again

HwyGuy

 

 

 

Link to comment

If you're not going to use a callback, you can remove that code.  Also, in your pasted example, the closing handlebar brace is coming before the "end" word.  You need to switch these around.  The function starts with "function()" and ends with "end" before you close the call to Wherigo.MessageBox.  Thus:

local stonesMessage = { "STONES: Removed:  "  .. removedStones ..  ", Chosen: " .. stonesItem ..  "Entries left: "  .. #stonesTable }
  
Wherigo.MessageBox{
  Text=stonesMessage, 
  Callback=function() 

  end
}

So, when it was saying there was an unexpected symbol near "}", it was saying the "}" was unexpected because it was expecting either some code/instructions or the "end" keyword.  Instead, it got a "}", which told it to close a statement before it could be closed because it needed "end" first.

 

 

If you don't need a callback for a message, you can simplify it:

local stonesMessage = { "STONES: Removed:  "  .. removedStones ..  ", Chosen: " .. stonesItem ..  "Entries left: "  .. #stonesTable }
  
Wherigo.MessageBox{
  Text=stonesMessage
}

 

Perhaps I shouldn't have done what I did in my comment in the example I gave you:

--Foxie is getting lazy with the callbacks
Wherigo.MessageBox{Text= stonesMessage, Callback = 
  function() 
    Wherigo.MessageBox{Text= beachMessage }
  end
}

I just wanted to avoid some complexity, make it easier to write, and make things supposedly easier for someone to understand.

 

The indentation I used in the example and above should have made it easier to know what begins and ends a statement.  Every time I go inside a statement, I increase the indent.

Link to comment
On 10/19/2023 at 8:35 PM, HwyGuy said:

 local stonesMessage = {"STONES: Removed:  "  .. removedStones ..  ", Chosen: " .. stonesItem ..  "Entries left: "  .. #stonesTable    }

Your error message comes from line 340, which seems to lack some dots in the end to make the string variable definition correct. I would also put on some quotes in the end to enclose the variables inside the text string, but I don't know if they are strictly necessary:

 

 local stonesMessage = {"STONES: Removed:  "  .. removedStones ..  ", Chosen: " .. stonesItem ..  ". Entries left: "  .. #stonesTable.. "" }

Link to comment

The Emulator really didn't like the 2 ".." at the end of the #stonesTable - so I left them off.

Unfortunately all I get when I run, and enter zone Hello is "Generic MessageBox"  showing up on the Emulator screen.  image.png.ad629e6af195dce7f61b76e70afc7c78.png

I have tried to send the stonesItem to Inventory but that doesn't work.   I attempted to send an Item to the Inventory if #tbl was nil and nothing went to inventory, so I am assuming the Table populated

I have added a second Zone with a Message to show when I arrive in there, but I have done that in the main part of the program. - It works!!  woo woo

I have added an Item (rocket) to put into the inventory, just to see if that worked , as that is where I eventually want to have the stonesItem reside. 

 

This is currently the entire Author Script that I have:


require "math"

math.randomseed( os.time())
math.random()
math.random()
math.random()

stonesTable = {}

function cartdemo:OnStart()
    Init()

end
 
function Init()

    table.insert(stonesTable, "Mick")
    table.insert(stonesTable, "Charlie")
    table.insert(stonesTable, "Keith")
    table.insert(stonesTable, "Bill")
    table.insert(stonesTable, "Brian")
 

end


function RemoveRandomItem(tbl)


    if #tbl == 0 then
        return
    end

    local idx = math.random(1, #tbl)
    return table.remove(tbl, idx)    
end

function GetRandomItem(tbl)

    if #tbl == 0 then
        return nil
    end

    local idx = math.random(1, #tbl)
    return tbl[idx]

end


function zoneHello:OnEnter()

  zitemrocket:MoveTo(Player)

    local stonesItem = GetRandomItem(stonesTable)

    if stonesItem == nil then
        stonesItem = 'none'
    
stonesitem:MoveTo(Player)
 
 
  end


 
local stonesMessage = {" Chosen: " ..stonesItem.. " ,  Length of Table = " ..#stonesTable }

    Wherigo.MessageBox{
        Text=stonesMessage
    
 
  }
 
 

 

Any suggestions of why Generic MesageBox  and not the desired Message? 

I am assuming the contents of the table are String values - can those be put into Inventory or do I need an IF:Then statement to check if the string name is THIS then the Item is THAT?

 

As always thanks - I feel I am slowly moving forward - unless that is me plunging towards the ground face first.

 

 

 

 

Link to comment

I now have an idea that the cartridge is not populating the stonesTable.  

Since the cartridge was not working using "Mick" , "Keith" etc as text strings - I made items of each of the names in the main part of the Earwigo program and then filled the table with :

table.insert(stonesTable, itemMick) etc       

 

When I ran the Emulator, I could go in and out of the 2 zones BUT still got the "Generic Message".  

 

When I attempted to put in a line - stonesItem:MoveTo(Player) I received an Error Message of "Attempt to call method "Move To" (a nil value)   Is this because there is no data in the table or is stonesItem a nil value for another reason?

 

Or am I barking up the wrong tree entirely?

 

Link to comment
--When you did this:
local stonesMessage = {" Chosen: " ..stonesItem.. " ,  Length of Table = " ..#stonesTable } 

--You should have done this:
local stonesMessage = " Chosen: " .. stonesItem .. " ,  Length of Table = " .. #stonesTable

--The top one creates a table/object with a string inside - or something like that (I am eyeballing it since I do not have much time).
--The bottom one creates a string.

 

Link to comment

Thank you for straightening out the "{" vs "(".

 

Changed that and received the Message of "Chosen: nil    Length 0.  when I entered the first zone.  Hmm not right!.   

That was using:

    table.insert(stonesTable, "Mick")      <--- used () did not work
    table.insert(stonesTable, "Charlie")
    table.insert(stonesTable, "Keith")
    table.insert(stonesTable, "Bill")
    table.insert(stonesTable, "Brian")

 

So I changed the input to   stonesTable = {itemMick, itemKeith, itemCharlie, itemBill, itemRonnie}   <--- used {} and did not work

Received the same output.

Changed the input to stonesTable = {43,49,89,33,76}    <--  used {} here & worked

Output was  Chosen 49  Length 5      WOW!    what I expected

Changed the input to 

table.insert(stonesTable, 43)                  <--- used () here and worked
table.insert(stonesTable, 33)
table.insert(stonesTable, 16)
table.insert(stonesTable, 19)
table.insert(stonesTable, 12)

 

Output was  Chosen 16  Length 5    again what i expected.

 

So both () and {} worked with numbers, and neither () or :{} worked for either of the text or items input

   

Therefore - a long way of saying - the insert of "Mick" or itemMick  did not result in a table.    Or at least one that can be accessed by me.     

I suppose I could just use numbers and an if:then statement for if 16 then Trevor Linden else  if 12 Stan Smyl else  etc - but that is awfully clunky.

 

Why did itemMick or "Mick" not work?    Everything I see says it should.  What changes does anyone see for me to get this to work?

 

Thanks again

HwyGuy

Link to comment

so - I got the Emulator to work with  stonesTable = {"Mick",  "Keith", "Charlie'", "Bill", "Ronnie"} - must have used the wrong brackets when I tried it the first couple of dozen times, but those are strings and I want to get items into a table.    Then I wish to store those items in a zone to be put into the Players Inventory.   I have been unable to do any of that with the strings.   

 

Can you access any of the functions in the Author Script from the "main" portion of the cartridge?  None of them appear in the Functions Tab or if you attempt to do a lua statement in a zone.

 

I had not planned to put everything into the zones at the beginning but more "on the fly" as you go through the cartridge - is that something I will not be able to do??  It is a change in philosophy but not a deal breaker I suppose.   But I still need to figure how to get the Items into a table and then into a zone from the Author Script.

 

If you initialize an item in the Items Tab - is that recognized in the Author Script?  It seems to me that you would have to have it initialized somewhere be  to be able to use it after coming from the Author Script to the main portion - is that correct?

Link to comment
On 11/1/2023 at 2:33 AM, HwyGuy said:

Can you access any of the functions in the Author Script from the "main" portion of the cartridge?

I guess that depends on the builder.  When I write cartridges, I tend to do the easy stuff in the builder, then sometimes drag it down into the author script section if I want it to call one of my functions.  Anyway, it depends on the builder whether it'll let you call author script and preserve what you wrote.  The challenging thing from a builder design standpoint is that you'd typically want to access cartridge objects from that function and pass them in, which means if the user later renames one of those objects, it's a pain to change the call into author script.

 

Anyway, objects can be inserted into a table just like strings.  I'm writing this without testing it, but something like this:

zitemSword = Wherigo.ZItem{Cartridge=cartFunWithTables}
zitemShield = Wherigo.ZItem{Cartridge=cartFunWithTables}
zitemArmor = Wherigo.ZItem{Cartridge=cartFunWithTables}

itemTable = {}

table.insert(itemTable, zitemSword)
table.insert(itemTable, zitemShield)
table.insert(itemTable, zitemArmor)

If you use Urwigo, don't tell it to obfuscate names when it makes the cartridge because it'll change the names of all your objects into something else.  You'll have a tough time keeping things straight.

 

Usually, when I build a cartridge, my workflow looks like this:

  1. Open a builder and create all the objects I want in the cartridge: zones, items, characters, timers, variables I want to persist when the game is saved and restored, etc.
  2. Add any media to the cartridge and associate it with the objects.
  3. Add any basic logic: messages and dialogs.
  4. After saving the cartridge, open it in a text editor.
  5. Write a function or two in author script. Save it.
  6. Reload the cartridge in the builder to make sure the lua file is still valid.
  7. Continue adding more code using the text editor, pausing every now and then to reopen it in the builder to make sure the lua file is still valid.
  8. Compile and play in an emulator to test what I've done so far.
  9. Continue adding more and testing until I'm done.

Any builder is good at generating objects, so I use one to start off with, then I switch over to adding all the other stuff.

 

If you want to look at some of my other cartridges for inspiration, I suggest you look at Battleship and Cacher Pursuit.  These use tables and are heavily commented for people to learn what I'm doing and what everything is.  In fact, here's one line from the Battleship cartridge:

local ship = { Name = name, Zones = { z }, IsSunk = false, Class = boatClass, Task = nil }

I have a table (object) with a property called "Name" (value of string), "Zones" containing an array of zones, "IsSunk" (boolean), "Class" (string), and "Task" (a Wherigo Task object).  All of that is loaded into a table (array) of similar battleships.

 

Finally, I'll leave you with this: it's just an array.  A string is a type of object (an array of characters) and a Wherigo item is a type of object (a table of properties no different from the "ship" one I showed above, which is just really a table of key/value pairs).

Link to comment

I have now moved along on this process.

I currently have 2 tables stones and beach filled in with 5 items each - 'Mick", 'Keith' etc

I have a function that chooses one of the items as the member that is being held outside the table - jail or something  RemoveRandomItem(stones) RemoveRandomItem(beach)

I have a second function that then chooses, but does not remove the member for each of the tables.      GetRandomItem(stones) GetRandomItem(beach)

I can now show this chosen members name to the player in a dialog box.  pickedstone  is   Keith   pickedbeach is Brian

BUT

What I cannot do is then transfer the chosen member - I think it is an item - to the Player with a move command, when I do so I just get the name that was assigned when the function chose it in the first place.

eg            lua statement local pickedstone = GetRandomItem(stones)

                lua statement local  pickedbeach = GetRandomItem(beach)

                local HiddenMessageBC =  'chose to show: '   .. pickedstone .. ', chosen to show: '   ..  pickedbeach

                Wherigo.MessageBox{Text= HiddenMessageBC}

 

will give             chosen to show   Keith     chosen to show    Brian         <===   what I was expecting

 

good so far

 

BUT if I attempt to

 zitempickedstone:MoveTo(Player)
 zitempickedbeach:MoveTo(Player)

 

what I get in Inventory is       pickedstone    pickedbeach    <=== not Keith  Brian

 

 

I have tried local itempickedstone and   local pickedstone,   -  emulator didn't like either

 

How do I get what is contained in pickedstone into inventory?  Is there a Value or Contains expression?

 

  Do I need a    this  ==  that    and    itemthis"MoveTo(Player) sort of thing?   If so = Why?

 

Is this something that can actually be done?

 

I have seen the Ranger Fox Clue cartridge and that is what I have been aiming at with all this, but with less following of the actual game of Clue.

 

Thanks again for spending time on this

 

 

 

 

 

Link to comment
3 hours ago, HwyGuy said:

How do I get what is contained in pickedstone into inventory?  Is there a Value or Contains expression?

 

I have seen the Ranger Fox Clue cartridge and that is what I have been aiming at with all this, but with less following of the actual game of Clue.

 

Thanks again for spending time on this

I'm looking at your first October 27th post for reference.  In it, your Init() function stores strings in the table.  So, that's what you're getting back when you call GetRandomItem.  You instead need to store the item objects (they're technically tables themselves, but I'll call them objects here to avoid confusion) in your table.  If you need to show the name of one of those items to a player, you can call the object's Name property.

 

Since you've seen my Clue cartridge, take a look at what I'm storing in the tables: they're the character, zone, and item objects themselves.  Also, make sure you have the code as of about four days ago.  Note I'm using my own "GetAllOfType" function instead of the inbuilt one because the iOS player app shows a lua exception when I try to get all of type ZItem or ZCharacter (or "character" or "item" for that matter).  Though I've yet to clean it up and add comments everywhere, you should be able to follow what's being done and what variable contains what because I tend to have a good sense at naming things.

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...