Jump to content

Help With Item


Nuwati
Followers 1

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.

Cheers,

-peter

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.

 

Matt

 

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.

 

Cheers,

-peter

 

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.Id="9a7be9ee-1245-45b9-b954-fad684d63fb5"
cartBookExample.Name="BookExample"
cartBookExample.Description=[[]]
cartBookExample.Visible=true
cartBookExample.Activity="Fiction"
cartBookExample.StartingLocationDescription=[[]]
cartBookExample.StartingLocation = Wherigo.INVALID_ZONEPOINT
cartBookExample.Version=""
cartBookExample.Company=""
cartBookExample.Author=""
cartBookExample.BuilderVersion="2.0.4628.3428"
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"
cartBookExample.TargetDevice="PocketPC"
cartBookExample.TargetDeviceVersion="0"
cartBookExample.StateId="1"
cartBookExample.CountryId="2"
cartBookExample.Complete=false
cartBookExample.UseLogging=false

-- Zones --

-- Characters --

-- Items --
zitemBook = Wherigo.ZItem(cartBookExample)
zitemBook.Id="3f67910b-1a0c-4f51-8de2-9b3dfab4e3b1"
zitemBook.Name="Book"
zitemBook.Description=[[This book can be picked up, opened, and read.]]
zitemBook.Visible=true
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.Id="e647c9e2-791d-44d3-a3a9-487ddf498379"
zitemBook.Commands.Grab.WorksWithAll = true
zitemBook.Commands.Open.Custom = true
zitemBook.Commands.Open.Id="fcd03e61-2d26-482d-b996-7a8094068854"
zitemBook.Commands.Open.WorksWithAll = true
zitemBook.Commands.Read.Custom = true
zitemBook.Commands.Read.Id="d2e171f5-6f17-41b7-872f-67ea3da90c0c"
zitemBook.Commands.Read.WorksWithAll = true
zitemBook.Commands.EnterCode.Custom = true
zitemBook.Commands.EnterCode.Id="ad0fa62a-51e7-48ed-938b-733aa4ab88c5"
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"
buildervar.UnscrambledCode.Data=[[]]
buildervar.UnscrambledCode.Description=[[]]


-- ZTimers --

-- Inputs --
zinputEnterCode = Wherigo.ZInput(cartBookExample)
zinputEnterCode.Id="85cc3b72-244e-45c2-b05f-2c6e1394ccd1"
zinputEnterCode.Name="EnterCode"
zinputEnterCode.Description=[[Allow the user to supply an unscrambled code.]]
zinputEnterCode.Visible=true
zinputEnterCode.InputType="Text"
zinputEnterCode.InputVariableId="9353f34e-75f5-45ff-8f38-ac1ed6321071"
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 --
zitemBook:MoveTo(Player)
end

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

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.]],}
else
if   zitemBook.Opened == true then
Wherigo.MessageBox{Text=[[The book is already open.]],}
else
zitemBook.Opened = true
end
end
end

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.]],}
else
Wherigo.MessageBox{Text=[[The scrambled code is "wighero".]],}
end
end

function zitemBook:OnEnterCode()
-- #GroupDescription=Script --
-- #Comment=Script Comment --
Wherigo.GetInput(zinputEnterCode)
end

function zinputEnterCode:OnGetInput(input)
UnscrambledCode = input
-- #GroupDescription=Script --
-- #Comment=Script Comment --
if   Wherigo.NoCaseEquals(UnscrambledCode,"Wherigo") then
Wherigo.MessageBox{Text=[[You did it!]],}
else
Wherigo.MessageBox{Text=[[Sorry, that's not correct.]],}
end
end
------End Builder Generated functions, Do not Edit, this will be overwritten------
-------------------------------------------------------------------------------
------Builder Generated callbacks, Do not Edit, this will be overwritten------
-------------------------------------------------------------------------------
--#LASTCALLBACKKEY=0#--
------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."

Or

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.

 

-peter

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...
Followers 1
×
×
  • Create New...