Jump to content

Help With Item


Recommended Posts

Since there are no built-in "book" objects in the Wherigo library, you will need to create your own book object and define the actions that it supports. So, to do what you describe, you will need to:


* Create a new ZItem called "Book" (or whatever you want to call it).

* Add a new action (command) to allow the user to "grab" it. You can call this "Take" or "Grab" for example.

* Define the new "Grab" action. A good idea of this type of action is to move it into the user's inventory.

* Add a new action to allow the user to open it (for example: "Open") and define the action. Depending on how fancy you want to get here, you might check to make sure the book is in the user's inventory before they are allowed to open it, and also keep track of whether the book is already opened, so it can't be opened again.

* Add a new action to allow the user to read or examine it (for example: "Read") and define the action. Again, you may want to check to make sure it is opened before allowing the user to read it, etc. The result of this action might be to show a MessageBox that contains the 'code' the user needs to figure out.

* Add a new action to allow the user to enter the the decoded variable. When this action is run, it could display a ZInput to allow the user to enter the text (or number) and then check the validity of it.

* Etc...


Hopefully this gives you an idea of what to do.



Link to comment

I second that. For instance, GeoGern posted in another thread a snippet of code showing how to get a user's altitude:


curAltitude = Player.ObjectLocation.altitude:GetValue("ft")


We don't have Intellisense when creating Lua scripts, so some detailed documentation would be really, really helpful to those who want to go beyond the builder application or at least know what all is available. Without knowing all the possibilities, people won't be able to create quality cartridges. And I can just imagine we'll see some interesting things later.


Now, just so long as Nuwati doesn't tell the Tube Torcher team about Wherigo. I can just imagine all the weird stuff I'll be required to do for either TT III or TT IV.

Link to comment

There is a Wherigo library? I could use a little more info...maybe a book on how to do this. I am not nocking this thing at all, but I bet we could all use a little more info on how these come togeather.




Hi Matt,


I guess I was a bit too technical with my previous post. The 'Wherigo library' is a bit of code in the Builder and Player that implements the basic functions and objects that you, the cartridge author, can use to create your own carts. So when I said that the Wherigo library does not have a built-in "book object," I meant that there isn't any base functionality that does exactly what you want.


While the Wherigo platform can certainly use some documentation and "how-to" tutorials (and I believe that some are being worked on by various Groundspeak Lackeys), none are available yet. So, the next best thing is just to dive in and try experimenting, learning from what others have posted, and asking questions.


To get you started, I created a very simple sample cartridge that contains the code for what I described in my previous post. It's not the best example in the world, and I would almost certainly do things differently in my own carts, but it is simple and it should give you something to start with and to look at. Just copy-n-paste the text from the ed of this post in to a new file (I called mine 'BookExample.lua') and then open that up in the Builder.





require "Wherigo"
ZonePoint = Wherigo.ZonePoint
Distance = Wherigo.Distance
Player = Wherigo.Player

-- #Author Directives Go Here# --
-- #End Author Directives# --

cartBookExample = Wherigo.ZCartridge()

-- MessageBox Callback Functions Table used by the Builder --
cartBookExample.MsgBoxCBFuncs = {}

-- Cartridge Info --
cartBookExample.StartingLocation = Wherigo.INVALID_ZONEPOINT
cartBookExample.CreateDate="1/8/2008 9:07:09 AM"
cartBookExample.PublishDate="1/1/0001 12:00:00 AM"
cartBookExample.UpdateDate="1/8/2008 9:09:37 AM"
cartBookExample.LastPlayedDate="1/1/0001 12:00:00 AM"

-- Zones --

-- Characters --

-- Items --
zitemBook = Wherigo.ZItem(cartBookExample)
zitemBook.Description=[[This book can be picked up, opened, and read.]]
zitemBook.ObjectLocation = Wherigo.INVALID_ZONEPOINT
zitemBook.Locked = false
zitemBook.Opened = false
zitemBook.Commands = {
 Grab = Wherigo.ZCommand{Text="Grab", CmdWith=false, Enabled=true},
 Open = Wherigo.ZCommand{Text="Open", CmdWith=false, Enabled=true},
 Read = Wherigo.ZCommand{Text="Read", CmdWith=false, Enabled=true},
 EnterCode = Wherigo.ZCommand{Text="Enter Code", CmdWith=false, Enabled=true},
zitemBook.Commands.Grab.Custom = true
zitemBook.Commands.Grab.WorksWithAll = true
zitemBook.Commands.Open.Custom = true
zitemBook.Commands.Open.WorksWithAll = true
zitemBook.Commands.Read.Custom = true
zitemBook.Commands.Read.WorksWithAll = true
zitemBook.Commands.EnterCode.Custom = true
zitemBook.Commands.EnterCode.WorksWithAll = true

-- Tasks --

-- Cartridge Variables --
UnscrambledCode = ""
cartBookExample.ZVariables = {UnscrambledCode = ""}

-- Builder Variables (to be read by the builder only) --
buildervar = {}
buildervar.UnscrambledCode = {}
buildervar.UnscrambledCode.Id ="9353f34e-75f5-45ff-8f38-ac1ed6321071"
buildervar.UnscrambledCode.Name = "UnscrambledCode"
buildervar.UnscrambledCode.Type = "String"

-- ZTimers --

-- Inputs --
zinputEnterCode = Wherigo.ZInput(cartBookExample)
zinputEnterCode.Description=[[Allow the user to supply an unscrambled code.]]
zinputEnterCode.Text=[[Please enter the unscrambled code.]]

-- Events/Conditions/Actions --

------Builder Generated functions, Do not Edit, this will be overwritten------

function cartBookExample:OnStart()
-- #GroupDescription=When the cart is started --
-- #Comment=When the cart is started --

function zitemBook:OnGrab()
-- #GroupDescription=Script --
-- #Comment=Script Comment --
if	not Player:Contains(zitemBook) then
Wherigo.MessageBox{Text=[[You already have the book!]],}

function zitemBook:OnOpen()
-- #GroupDescription=Script --
-- #Comment=Script Comment --
if	not Player:Contains(zitemBook) then
Wherigo.MessageBox{Text=[[You have to be holding the book in order to open it.]],}
if   zitemBook.Opened == true then
Wherigo.MessageBox{Text=[[The book is already open.]],}
zitemBook.Opened = true

function zitemBook:OnRead()
-- #GroupDescription=Script --
-- #Comment=Script Comment --
if	not Player:Contains(zitemBook) or zitemBook.Opened ~= true then
Wherigo.MessageBox{Text=[[You can't read what you don't have and is not open.]],}
Wherigo.MessageBox{Text=[[The scrambled code is "wighero".]],}

function zitemBook:OnEnterCode()
-- #GroupDescription=Script --
-- #Comment=Script Comment --

function zinputEnterCode:OnGetInput(input)
UnscrambledCode = input
-- #GroupDescription=Script --
-- #Comment=Script Comment --
if   Wherigo.NoCaseEquals(UnscrambledCode,"Wherigo") then
Wherigo.MessageBox{Text=[[You did it!]],}
Wherigo.MessageBox{Text=[[Sorry, that's not correct.]],}
------End Builder Generated functions, Do not Edit, this will be overwritten------
------Builder Generated callbacks, Do not Edit, this will be overwritten------
------End Builder Generated callbacks, Do not Edit, this will be overwritten------
-- #Author Functions Go Here# --
-- #End Author Functions# --
-- Nothing after this line --
return cartBookExample

Link to comment

How do I make a new file. Again, not trying to be a pain, just hanging in there.


In your Windows File Explorer, click on the File->New menu and select something like "Text Document."


Using the Wherigo Builder, create a new cartridge (File->New Cartridge...), give it a name, close the Cartridge Base Information window, save the cartridge


Then, edit the new cartridge script file you just saved/created in Notepad and replace the contents of the file with the code from this thread.


Be sure that the file you create has a '.lua' file suffix, otherwise the Builder will not see it and will not open it.



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.

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.

  • Create New...