Jump to content

Randomization


Shriekback

Recommended Posts

Ok, since there's not a definitive list of functions available yet for Wherigo, I will ask this: is there a "variable randomization" function available? Whereas I definitely see Wherigo as a way to revitalize (resurrect perhaps?) the adventure game genre, I also see this as a neat RPG opportunity. Roll a die to see if you hit or are hit type of thing.

 

I guess that leads to another question. Will there ever be a guide to creating these cartridges in a text editor and then simply compiling them into the .lua format?

 

Anyway, thanks in advance!

Link to comment

There currently isn't any public/documented list of Wherigo-specific APIs for creating cartridges in a text editor. However, I can tell you it is definitely possible, as I have created a number of cartridges w/o the aid of the Builder.

 

Since cartridges are just Lua script files that make use of both the standard Lua libraries and a custom Wherigo library, all that is needed is access to the Wherigo "Linker" that will turn the Lua script and associated media resources into a GWC file. This "Linker" is embedded in to the Builder and will eventually be exposed via a web-service call on the Wherigo.com site.

 

However, this is getting ahead of the horse, so-to-speak. My advice for now would be to stick to the Builder and see what is possible with it. If you are feeling like an "intrepid hacker" you might pick up quite a bit of the Wherigo-specific Lua syntax simply by examining what the Builder produces. And hopefully the future will bring proper documentation and support for "advanced" cartridge building using your favourite text-editor and OS.

 

As a specific answer to your question about a "randomisation function," the Lua "math" library contains a random() API that will generate random numbers. In fact, this is used by the Tutorial cartridge.

 

Cheers,

-peter

Link to comment

Yeah, in the Lua source, I created a variable called "Random" and tried to set its value when the player enters a zone. This produces an exception when the line runs in the emulator.

 

The line is:

Random = math.random(0,100)

 

The random function was supposed to return a number from zero to a hundred.

 

Try going to the following site for more on the math function:

http://lua-users.org/wiki/MathLibraryTutorial

Link to comment

Yeah, in the Lua source, I created a variable called "Random" and tried to set its value when the player enters a zone. This produces an exception when the line runs in the emulator.

 

Can you provide any more details about the exception that was generated? The line you provided looks okay. Also, the Lua "math" library is not loaded by default, so be sure to "require" the math library before using any functions from it. In the Tutorial cartridge, this is done near the top of the file (in the "Author Directives" section) by this line:

 

require "math"

 

Cheers,

-peter

Link to comment

Wow! Great information and fast!!! Thanks!

 

Like you said, I am NOT a L33T Haxor, so you're right, I'm just gonna stick with the basics for now. I'm sure later on I can try delving into the Lua language a bit more. But for now, I'll stick with the easy stuff.

 

Great system! Thanks!

Link to comment

Yeah, in the Lua source, I created a variable called "Random" and tried to set its value when the player enters a zone. This produces an exception when the line runs in the emulator.

 

Can you provide any more details about the exception that was generated? The line you provided looks okay. Also, the Lua "math" library is not loaded by default, so be sure to "require" the math library before using any functions from it. In the Tutorial cartridge, this is done near the top of the file (in the "Author Directives" section) by this line:

 

require "math"

 

Cheers,

-peter

 

The latter part of my post is the source of one of my tests, a complete cartridge. You'll see a few places I played around with the random function. Move the player to the parking zone and watch the exception trigger when it tries to assign a random value to the Random variable. Referencing the variable as either "Random" or "buildervar.Random" will produce the same effect. The exception is "attempt to index global variable 'math' (nil value)".

 

Now, I don't know if Lua is case sensitive (I program with C#), so perhaps the exception really occurs because I named a variable the same as a function. I renamed the variable to "Ran" and the exception repeated.

 

Okay. Then what about "math.random" being the wrong way to reference the function? I tried referencing the function only, "random(0,100)". Same exception.

 

Nice exception screen, though. The graphic is very user friendly. Compliments.

 

====================================================

And, now, the code:

====================================================

 

require "Wherigo"

require "math"

ZonePoint = Wherigo.ZonePoint

Distance = Wherigo.Distance

Player = Wherigo.Player

 

-- #Author Directives Go Here# --

-- #End Author Directives# --

 

cartTest3 = Wherigo.ZCartridge()

 

-- MessageBox Callback Functions Table used by the Builder --

cartTest3.MsgBoxCBFuncs = {}

 

-- Cartridge Info --

cartTest3.Id="c183a2f5-6ec4-45c0-b164-6af81985f473"

cartTest3.Name="Test 3"

cartTest3.Description=[[A time trial along the trail]]

cartTest3.Visible=true

cartTest3.Activity="Puzzle"

cartTest3.StartingLocationDescription=[[]]

cartTest3.StartingLocation = ZonePoint(36.1423999945323,-79.8561833063761,0)

cartTest3.Version=".01"

cartTest3.Company="Ranger Fox Adventures, Ltd."

cartTest3.Author="Ranger Fox"

cartTest3.BuilderVersion="2.0.4703.3295"

cartTest3.CreateDate="1/4/2008 3:43:54 PM"

cartTest3.PublishDate="1/1/0001 12:00:00 AM"

cartTest3.UpdateDate="1/4/2008 4:53:37 PM"

cartTest3.LastPlayedDate="1/1/0001 12:00:00 AM"

cartTest3.TargetDevice="PocketPC"

cartTest3.TargetDeviceVersion="0"

cartTest3.StateId="1"

cartTest3.CountryId="2"

cartTest3.Complete=false

cartTest3.UseLogging=false

 

-- Zones --

zoneParkingarea = Wherigo.Zone(cartTest3)

zoneParkingarea.Id="52fa9078-04ca-4e40-8607-2c6d88cd3fba"

zoneParkingarea.Name="Parking area"

zoneParkingarea.Description=[[Park here]]

zoneParkingarea.Visible=true

zoneParkingarea.DistanceRange = Distance(-1, "feet")

zoneParkingarea.ShowObjects="OnEnter"

zoneParkingarea.ProximityRange = Distance(100, "feet")

zoneParkingarea.AllowSetPositionTo=false

zoneParkingarea.Active=true

zoneParkingarea.Points = {

ZonePoint(36.14225,-79.85592,0),

ZonePoint(36.14243,-79.8558,0),

ZonePoint(36.14272,-79.85629,0),

ZonePoint(36.14259,-79.85649,0)

}

zoneParkingarea.OriginalPoint = ZonePoint(36.1422499974569,-79.8559166590373,0)

zoneParkingarea.DistanceRangeUOM = "Feet"

zoneParkingarea.ProximityRangeUOM = "Feet"

zoneParkingarea.OutOfRangeName = ""

zoneParkingarea.InRangeName = ""

 

zonePlankbridge = Wherigo.Zone(cartTest3)

zonePlankbridge.Id="2373f3e4-0eb3-4849-9450-db9c5f317962"

zonePlankbridge.Name="Plank bridge"

zonePlankbridge.Description=[[]]

zonePlankbridge.Visible=false

zonePlankbridge.DistanceRange = Distance(-1, "feet")

zonePlankbridge.ShowObjects="OnEnter"

zonePlankbridge.ProximityRange = Distance(10, "feet")

zonePlankbridge.AllowSetPositionTo=false

zonePlankbridge.Active=false

zonePlankbridge.Points = {

ZonePoint(36.14279,-79.8563,0),

ZonePoint(36.14307,-79.85607,0),

ZonePoint(36.14323,-79.85622,0),

ZonePoint(36.14298,-79.85649,0)

}

zonePlankbridge.OriginalPoint = ZonePoint(36.1427833398183,-79.8562999725342,0)

zonePlankbridge.DistanceRangeUOM = "Feet"

zonePlankbridge.ProximityRangeUOM = "Feet"

zonePlankbridge.OutOfRangeName = ""

zonePlankbridge.InRangeName = ""

 

zoneRailroadSign = Wherigo.Zone(cartTest3)

zoneRailroadSign.Id="7cbfc5d9-094b-4cd6-a4ef-17a1bcbdf798"

zoneRailroadSign.Name="Railroad Sign"

zoneRailroadSign.Description=[[]]

zoneRailroadSign.Visible=false

zoneRailroadSign.DistanceRange = Distance(-1, "feet")

zoneRailroadSign.ShowObjects="OnEnter"

zoneRailroadSign.ProximityRange = Distance(10, "feet")

zoneRailroadSign.AllowSetPositionTo=false

zoneRailroadSign.Active=false

zoneRailroadSign.Points = {

ZonePoint(36.15314,-79.855,0),

ZonePoint(36.15305,-79.85531,0),

ZonePoint(36.1533,-79.8555,0),

ZonePoint(36.15349,-79.85524,0)

}

zoneRailroadSign.OriginalPoint = ZonePoint(36.1531333287557,-79.8549999872843,0)

zoneRailroadSign.DistanceRangeUOM = "Feet"

zoneRailroadSign.ProximityRangeUOM = "Feet"

zoneRailroadSign.OutOfRangeName = ""

zoneRailroadSign.InRangeName = ""

 

zoneAquifinaArea = Wherigo.Zone(cartTest3)

zoneAquifinaArea.Id="94701d65-d574-44ff-a8a4-d45dd5e48944"

zoneAquifinaArea.Name="Aquifina Area"

zoneAquifinaArea.Description=[[]]

zoneAquifinaArea.Visible=false

zoneAquifinaArea.DistanceRange = Distance(-1, "feet")

zoneAquifinaArea.ShowObjects="OnEnter"

zoneAquifinaArea.ProximityRange = Distance(10, "feet")

zoneAquifinaArea.AllowSetPositionTo=false

zoneAquifinaArea.Active=false

zoneAquifinaArea.Points = {

ZonePoint(36.15193,-79.85451,0),

ZonePoint(36.15215,-79.85462,0),

ZonePoint(36.15208,-79.85485,0),

ZonePoint(36.1518,-79.85459,0)

}

zoneAquifinaArea.OriginalPoint = ZonePoint(36.1519333362579,-79.8545166651408,0)

zoneAquifinaArea.DistanceRangeUOM = "Feet"

zoneAquifinaArea.ProximityRangeUOM = "Feet"

zoneAquifinaArea.OutOfRangeName = ""

zoneAquifinaArea.InRangeName = ""

 

-- Characters --

 

-- Items --

zitemRandom = Wherigo.ZItem(cartTest3)

zitemRandom.Id="5ac3fd70-474b-497d-b8d1-aa84678f6ba5"

zitemRandom.Name="Random"

zitemRandom.Description=[[]]

zitemRandom.Visible=false

zitemRandom.ObjectLocation = Wherigo.INVALID_ZONEPOINT

zitemRandom.Locked = false

zitemRandom.Opened = false

zitemRandom.Commands = {

GetRandom = Wherigo.ZCommand{Text="GetRandom", CmdWith=false, Enabled=true, EmptyTargetListText="Nothing available"},

}

zitemRandom.Commands.GetRandom.Custom = true

zitemRandom.Commands.GetRandom.Id="9d38f63f-760f-4fad-baeb-2a3e19ef9857"

zitemRandom.Commands.GetRandom.WorksWithAll = true

 

-- Tasks --

ztaskFindtheparkingarea = Wherigo.ZTask(cartTest3)

ztaskFindtheparkingarea.Id="4259783b-c0c6-492b-9690-96456bd8bec9"

ztaskFindtheparkingarea.Name="Find the parking area"

ztaskFindtheparkingarea.Description=[[]]

ztaskFindtheparkingarea.Visible=true

ztaskFindtheparkingarea.Active=true

ztaskFindtheparkingarea.Complete=false

ztaskFindtheparkingarea.CorrectState = "None"

 

ztaskFindrailroad = Wherigo.ZTask(cartTest3)

ztaskFindrailroad.Id="a12be009-b3fe-40f4-9459-980b244dec34"

ztaskFindrailroad.Name="Find railroad"

ztaskFindrailroad.Description=[[]]

ztaskFindrailroad.Visible=false

ztaskFindrailroad.Active=false

ztaskFindrailroad.Complete=false

ztaskFindrailroad.CorrectState = "None"

 

ztaskFindAquifinaarea = Wherigo.ZTask(cartTest3)

ztaskFindAquifinaarea.Id="58653b15-4628-4d77-a6ae-f3a95420f32c"

ztaskFindAquifinaarea.Name="Find Aquifina area"

ztaskFindAquifinaarea.Description=[[]]

ztaskFindAquifinaarea.Visible=false

ztaskFindAquifinaarea.Active=false

ztaskFindAquifinaarea.Complete=false

ztaskFindAquifinaarea.CorrectState = "None"

 

ztaskGettotheplankbridge = Wherigo.ZTask(cartTest3)

ztaskGettotheplankbridge.Id="59095708-f9e8-466e-8ef5-0cb5f689ac34"

ztaskGettotheplankbridge.Name="Get to the plank bridge"

ztaskGettotheplankbridge.Description=[[]]

ztaskGettotheplankbridge.Visible=false

ztaskGettotheplankbridge.Active=false

ztaskGettotheplankbridge.Complete=false

ztaskGettotheplankbridge.CorrectState = "None"

 

-- Cartridge Variables --

Random = 0

TimerExpired = false

cartTest3.ZVariables = {Random = 0, TimerExpired = false}

 

-- Builder Variables (to be read by the builder only) --

buildervar = {}

buildervar.Random = {}

buildervar.Random.Id ="763ea73a-b54f-4ac2-bf1c-a5d230b4f292"

buildervar.Random.Name = "Random"

buildervar.Random.Type = "Number"

buildervar.Random.Data=[[0]]

buildervar.Random.Description=[[]]

 

buildervar.TimerExpired = {}

buildervar.TimerExpired.Id ="0dfd5fe7-7c9d-4d09-b9b4-9a6fd9e61da3"

buildervar.TimerExpired.Name = "Timer Expired"

buildervar.TimerExpired.Type = "Flag"

buildervar.TimerExpired.Data=[[False]]

buildervar.TimerExpired.Description=[[]]

 

-- ZTimers --

ztimerStopwatch = Wherigo.ZTimer(cartTest3)

ztimerStopwatch.Id="2d6873df-7ed9-4608-88d7-4768c6b35ac4"

ztimerStopwatch.Name="Stopwatch"

ztimerStopwatch.Description=[[]]

ztimerStopwatch.Visible=true

ztimerStopwatch.Duration=600

ztimerStopwatch.Type="Countdown"

 

-- Inputs --

 

--

-- Events/Conditions/Actions --

--

 

-------------------------------------------------------------------------------

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

-------------------------------------------------------------------------------

 

function zoneParkingarea:OnEnter()

-- #GroupDescription=Enter the parking area --

-- #Comment=Enter the parking area Comment --

ztaskFindtheparkingarea.Complete = true

Wherigo.MessageBox{Text=[[You found the parking area. Now, go to the railroad sign.]],}

zoneRailroadSign.Active = true

ztaskFindrailroad.Active = true

zoneRailroadSign.Visible = true

ztaskFindrailroad.Visible = true

zoneRailroadSign.Visible = true

Random = math.random(0,100)

end

 

function zoneRailroadSign:OnEnter()

-- #GroupDescription=Player enters the railroad zone --

-- #Comment=Player enters the railroad zone Comment --

Wherigo.MessageBox{Text=[[Good. You found the railroad sign.

Now, find the Aquifina rest stop.]],}

ztaskFindrailroad.Complete = true

ztaskFindAquifinaarea.Active = true

zoneAquifinaArea.Active = true

zoneAquifinaArea.Visible = true

ztaskFindAquifinaarea.Visible = true

end

 

function zoneAquifinaArea:OnEnter()

-- #GroupDescription=Enter the Aquifina area --

-- #Comment=Enter the Aquifina area Comment --

ztaskFindAquifinaarea.Complete = true

zonePlankbridge.Active = true

zonePlankbridge.Visible = true

ztaskGettotheplankbridge.Visible = true

ztaskGettotheplankbridge.Active = true

Wherigo.MessageBox{Text=[[Great!

Now, it's a time attack to the plank bridge. You have ten minutes.]],}

end

 

function zoneAquifinaArea:OnExit()

-- #GroupDescription=Exit the Aquifina zone --

-- #Comment=Exit the Aquifina zone Comment --

ztimerStopwatch:Start()

zoneAquifinaArea.Active = false

zoneAquifinaArea.Visible = false

end

 

function ztimerStopwatch:OnTick()

-- #GroupDescription=Timer expires --

-- #Comment=Timer expires Comment --

TimerExpired = true

Wherigo.MessageBox{Text=[[Too late!]],}

ztaskGettotheplankbridge.Complete = false

end

 

function zonePlankbridge:OnEnter()

-- #GroupDescription=Enter the plank bridge --

-- #Comment=Enter the plank bridge Comment --

if ztimerStopwatch.Duration > 0 then

Wherigo.MessageBox{Text=[[Great! Good job.]],}

ztaskGettotheplankbridge.Complete = true

end

end

 

function cartTest3:OnStart()

-- #GroupDescription=Start cartridge --

-- #Comment=Start cartridge Comment --

zoneParkingarea.Active = true

zoneParkingarea.Visible = true

ztaskFindtheparkingarea.Active = true

ztaskFindtheparkingarea.Visible = true

end

 

function zoneRailroadSign:OnExit()

-- #GroupDescription=Exit railroad sign - hide the railroad stuff --

-- #Comment=Exit railroad sign - hide the railroad stuff Comment --

zoneRailroadSign.Visible = false

zoneRailroadSign.Active = false

end

 

function zitemRandom:OnGetRandom()

-- #GroupDescription=Get random number --

-- #Comment=Get random number Comment --

Random = math.random(0,100)

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 cartTest3

Link to comment

The latter part of my post is the source of one of my tests, a complete cartridge. You'll see a few places I played around with the random function. Move the player to the parking zone and watch the exception trigger when it tries to assign a random value to the Random variable. Referencing the variable as either "Random" or "buildervar.Random" will produce the same effect. The exception is "attempt to index global variable 'math' (nil value)".

 

Now, I don't know if Lua is case sensitive (I program with C#), so perhaps the exception really occurs because I named a variable the same as a function. I renamed the variable to "Ran" and the exception repeated.

 

Okay. Then what about "math.random" being the wrong way to reference the function? I tried referencing the function only, "random(0,100)". Same exception.

 

Hrm. Now I am puzzled. I ran your code on my machine and I do not get an exception; it runs just fine. In fact, I can "watch" the Random variable change to different values as I move the player in and out and in the Parking Area Zone.

 

First, a couple of answers to questions you posed:

Yes, Lua is case-sensitive, so random is not the same as Random.

Lua does not have namespaces like C#, but it achieves a similar concept thru the use of tables. So, the 'random()' function is in the 'math' library and (because of the way the library was "imported") needs to be referenced via 'math.random()' and not just 'random()'. In fact, if you had a variable (or function... in Lua they are the same thing: functions are a "first-class" data type) in the 'global' table (same place that Random "lives) named 'random' it would not be the same thing as 'math.random' (unless you explicitly "aliased" random to refer to math.random).

 

So... what to do now?

 

My first suggestion is to make sure that you are re-compiling the script into GWC format each time you make changes to the file. When you launch the Wherigo Emulator, it does not automatically re-compile the cartridge. You have to do that part manually. It is possible that you are getting the nil value exception each time because even though you are making code changes, you're always emulating the same original script.

 

If that is not it (because you already knew this, or you gave it a try and you're still getting an exception), then perhaps you have a corrupt installation of the Builder. This seems highly unlikely, since it shouldn't run at all, rather than run but complain about the math library being nil.

 

And if all else fails, perhaps you can send me the GWC file that you have compiled that is giving you the exception and I can pick thru it.

 

Also, in case you are not aware, there is an excellent online Lua book that you might find helpful:

http://www.lua.org/pil/

 

Cheers,

-peter

Link to comment

Thank you, GeoGern, for the information. Here's your answer to the random question, Wumpus:

 

Suppose you want to make a random number. Here's how to do it:

 

Define a variable in the builder and call it whatever you want. I will call it "Random" for this example.

 

Next, define whatever event you want that will be dependent upon the random number. For purposes of this example, I will keep it simple. This step will show you how to create a character who will give you a random number every time you talk to him/her. The character will then tell you if the number is low (<50) or high (>=50 to keep it simple).

 

To create the character outlined above, to the following: Select "Characters", click "Add", and give the character a name. Next, look at the bottom right-hand corner under "Commands". Create one called "Talk". After that, click the "Events" tab and you will see "When talk occurs". Select it and click "New".

-- I originally typed this post to display two message boxes, one to show the random number and one to tell if it is a higher or lower number. However, showing two message boxes one after another does not work well. It'll show the boxes, but the first will give way to the next without requiring user input. Instead, we'll create one message box to display and it will say the number AND if it is a higher or lower number.

-- Let's first begin with defining PART of the message where the character tells you the number:

-- Add an if-then-else block. In step one, select "Compare an Object" yadda-yadda-yadda. For each of the three arguments, in this order, specify the following: the Random variable, "Greater than or equal to", and the value 50. The line should now read "If Random Greater Than or Equal To 50". Click "OK".

--We're back to the programming block screen. Highlight your if statement and click "Add an action". This is what happens if Random is greater than or equal to 50. Select "Show a message to the player" and make the message say " is a higher number" (space included). Now, create another message to the user that will say " is a lower number". Don't forget to highlight "else" before you click "Add an Action".

 

Now, we're going to edit the code directly. Hacking time! Click "OK" until you're back to the main screen. Save your cartridge. You don't have to close it.

 

Open your .lua cartridge file in Notepad. First, type the following line at the top of the file:

requires "math"

WARNING: You will have to insert the above statement manually after EVERY TIME you save your cartridge. It keeps losing that statement, which was the cause of my confusion. Odd, but it happens.

 

Now, do a search for the string " is a higher number"--what you typed for the character to say to you. You will see the following:

Wherigo.MessageBox{Text=[[ is a higher number.]],}

Remember that variable you defined to hold the random number? Change the statement likewise to mimic the following:

Wherigo.MessageBox{Text=Random .. [[ is a higher number.]],}

In Lua, apparently, ".." is the equivalent to "&" in VB and "+" in C#. String concatenation.

 

Do the same thing for the lower number.

 

Look at your "if" statement and be sure it reads like mine. I didn't have an operator in mine and had to edit it:

if Random >= 50 then

 

And, now, the last step. Include the following code above "if" statement. This is what assigns the random number. The first digit is the lower bound and the second the upper bound of your random number. Both numbers are inclusive: it will return a 0 or 100 within the random number set. Feel free to use other variables if you'd like.

Random = math.random(0,100)

 

Save the file and reload it into the Wherigo Builder application, compile it to your machine, and run it in the emulator.

 

 

 

Here's my test code. There are other things in it, but pay attention to the code under the function "function zcharacterRandomGuy:OnTalk()". Copy this to a new text file and name it "test3.lua". Using my file, which has a lot of other test junk in it, move the player's position to the closest zone, right off the road. You'll see a character listed called "Random Guy". Talk to the character multiple times to see different random numbers.

 

From this example, you should now understand how to insert a random number into the code.

 

If you have any other questions, it seems the Groundspeak crew are very eager to answer them. Compliments to them for treating us, the innovator market group, well. I'll be hanging out around here and will perhaps come out with a test open source cartridge for people to learn from it. Seems like I have another programming project other than the Statbar Modifier to work on.

 

=================================================

=================================================

 

require "Wherigo"

require "math"

ZonePoint = Wherigo.ZonePoint

Distance = Wherigo.Distance

Player = Wherigo.Player

 

-- #Author Directives Go Here# --

-- #End Author Directives# --

 

cartTest3 = Wherigo.ZCartridge()

 

-- MessageBox Callback Functions Table used by the Builder --

cartTest3.MsgBoxCBFuncs = {}

 

-- Cartridge Info --

cartTest3.Id="c183a2f5-6ec4-45c0-b164-6af81985f473"

cartTest3.Name="Test 3"

cartTest3.Description=[[A time trial along the trail]]

cartTest3.Visible=true

cartTest3.Activity="Puzzle"

cartTest3.StartingLocationDescription=[[]]

cartTest3.StartingLocation = ZonePoint(36.1423999945323,-79.8561833063761,0)

cartTest3.Version=".01"

cartTest3.Company="Ranger Fox Adventures, Ltd."

cartTest3.Author="Ranger Fox"

cartTest3.BuilderVersion="2.0.4704.3539"

cartTest3.CreateDate="1/4/2008 3:43:54 PM"

cartTest3.PublishDate="1/1/0001 12:00:00 AM"

cartTest3.UpdateDate="1/4/2008 4:53:37 PM"

cartTest3.LastPlayedDate="1/1/0001 12:00:00 AM"

cartTest3.TargetDevice="PocketPC"

cartTest3.TargetDeviceVersion="0"

cartTest3.StateId="1"

cartTest3.CountryId="2"

cartTest3.Complete=false

cartTest3.UseLogging=false

 

-- Zones --

zoneParkingarea = Wherigo.Zone(cartTest3)

zoneParkingarea.Id="52fa9078-04ca-4e40-8607-2c6d88cd3fba"

zoneParkingarea.Name="Parking area"

zoneParkingarea.Description=[[Park here]]

zoneParkingarea.Visible=true

zoneParkingarea.DistanceRange = Distance(-1, "feet")

zoneParkingarea.ShowObjects="OnEnter"

zoneParkingarea.ProximityRange = Distance(100, "feet")

zoneParkingarea.AllowSetPositionTo=false

zoneParkingarea.Active=true

zoneParkingarea.Points = {

ZonePoint(36.14225,-79.85592,0),

ZonePoint(36.14243,-79.8558,0),

ZonePoint(36.14272,-79.85629,0),

ZonePoint(36.14259,-79.85649,0)

}

zoneParkingarea.OriginalPoint = ZonePoint(36.1422499974569,-79.8559166590373,0)

zoneParkingarea.DistanceRangeUOM = "Feet"

zoneParkingarea.ProximityRangeUOM = "Feet"

zoneParkingarea.OutOfRangeName = ""

zoneParkingarea.InRangeName = ""

 

zonePlankbridge = Wherigo.Zone(cartTest3)

zonePlankbridge.Id="2373f3e4-0eb3-4849-9450-db9c5f317962"

zonePlankbridge.Name="Plank bridge"

zonePlankbridge.Description=[[]]

zonePlankbridge.Visible=false

zonePlankbridge.DistanceRange = Distance(-1, "feet")

zonePlankbridge.ShowObjects="OnEnter"

zonePlankbridge.ProximityRange = Distance(10, "feet")

zonePlankbridge.AllowSetPositionTo=false

zonePlankbridge.Active=false

zonePlankbridge.Points = {

ZonePoint(36.14279,-79.8563,0),

ZonePoint(36.14307,-79.85607,0),

ZonePoint(36.14323,-79.85622,0),

ZonePoint(36.14298,-79.85649,0)

}

zonePlankbridge.OriginalPoint = ZonePoint(36.1427833398183,-79.8562999725342,0)

zonePlankbridge.DistanceRangeUOM = "Feet"

zonePlankbridge.ProximityRangeUOM = "Feet"

zonePlankbridge.OutOfRangeName = ""

zonePlankbridge.InRangeName = ""

 

zoneRailroadSign = Wherigo.Zone(cartTest3)

zoneRailroadSign.Id="7cbfc5d9-094b-4cd6-a4ef-17a1bcbdf798"

zoneRailroadSign.Name="Railroad Sign"

zoneRailroadSign.Description=[[]]

zoneRailroadSign.Visible=false

zoneRailroadSign.DistanceRange = Distance(-1, "feet")

zoneRailroadSign.ShowObjects="OnEnter"

zoneRailroadSign.ProximityRange = Distance(10, "feet")

zoneRailroadSign.AllowSetPositionTo=false

zoneRailroadSign.Active=false

zoneRailroadSign.Points = {

ZonePoint(36.15314,-79.855,0),

ZonePoint(36.15305,-79.85531,0),

ZonePoint(36.1533,-79.8555,0),

ZonePoint(36.15349,-79.85524,0)

}

zoneRailroadSign.OriginalPoint = ZonePoint(36.1531333287557,-79.8549999872843,0)

zoneRailroadSign.DistanceRangeUOM = "Feet"

zoneRailroadSign.ProximityRangeUOM = "Feet"

zoneRailroadSign.OutOfRangeName = ""

zoneRailroadSign.InRangeName = ""

 

zoneAquifinaArea = Wherigo.Zone(cartTest3)

zoneAquifinaArea.Id="94701d65-d574-44ff-a8a4-d45dd5e48944"

zoneAquifinaArea.Name="Aquifina Area"

zoneAquifinaArea.Description=[[]]

zoneAquifinaArea.Visible=false

zoneAquifinaArea.DistanceRange = Distance(-1, "feet")

zoneAquifinaArea.ShowObjects="OnEnter"

zoneAquifinaArea.ProximityRange = Distance(10, "feet")

zoneAquifinaArea.AllowSetPositionTo=false

zoneAquifinaArea.Active=false

zoneAquifinaArea.Points = {

ZonePoint(36.15193,-79.85451,0),

ZonePoint(36.15215,-79.85462,0),

ZonePoint(36.15208,-79.85485,0),

ZonePoint(36.1518,-79.85459,0)

}

zoneAquifinaArea.OriginalPoint = ZonePoint(36.1519333362579,-79.8545166651408,0)

zoneAquifinaArea.DistanceRangeUOM = "Feet"

zoneAquifinaArea.ProximityRangeUOM = "Feet"

zoneAquifinaArea.OutOfRangeName = ""

zoneAquifinaArea.InRangeName = ""

 

-- Characters --

zcharacterRandomGuy = Wherigo.ZCharacter{Cartridge=cartTest3, Container=zoneParkingarea}

zcharacterRandomGuy.Id="525cc893-ac19-4e1c-9bba-e87031422b94"

zcharacterRandomGuy.Name="Random Guy"

zcharacterRandomGuy.Description=[[]]

zcharacterRandomGuy.Visible=true

zcharacterRandomGuy.Gender="Male"

zcharacterRandomGuy.Type="NPC"

zcharacterRandomGuy.ObjectLocation = ZonePoint(36.1424918494855,-79.8561522764714,360)

zcharacterRandomGuy.Commands = {

Talk = Wherigo.ZCommand{Text="Talk", CmdWith=false, Enabled=true, EmptyTargetListText="Nothing available"},

}

zcharacterRandomGuy.Commands.Talk.Custom = true

zcharacterRandomGuy.Commands.Talk.Id="03330ea2-27d2-4242-92b2-33122efaee47"

zcharacterRandomGuy.Commands.Talk.WorksWithAll = true

 

-- Items --

zitemRandom = Wherigo.ZItem(cartTest3)

zitemRandom.Id="5ac3fd70-474b-497d-b8d1-aa84678f6ba5"

zitemRandom.Name="Random"

zitemRandom.Description=[[]]

zitemRandom.Visible=false

zitemRandom.ObjectLocation = Wherigo.INVALID_ZONEPOINT

zitemRandom.Locked = false

zitemRandom.Opened = false

zitemRandom.Commands = {

GetRandom = Wherigo.ZCommand{Text="GetRandom", CmdWith=false, Enabled=true, EmptyTargetListText="Nothing available"},

}

zitemRandom.Commands.GetRandom.Custom = true

zitemRandom.Commands.GetRandom.Id="9d38f63f-760f-4fad-baeb-2a3e19ef9857"

zitemRandom.Commands.GetRandom.WorksWithAll = true

 

-- Tasks --

ztaskFindtheparkingarea = Wherigo.ZTask(cartTest3)

ztaskFindtheparkingarea.Id="4259783b-c0c6-492b-9690-96456bd8bec9"

ztaskFindtheparkingarea.Name="Find the parking area"

ztaskFindtheparkingarea.Description=[[]]

ztaskFindtheparkingarea.Visible=true

ztaskFindtheparkingarea.Active=true

ztaskFindtheparkingarea.Complete=false

ztaskFindtheparkingarea.CorrectState = "None"

 

ztaskFindrailroad = Wherigo.ZTask(cartTest3)

ztaskFindrailroad.Id="a12be009-b3fe-40f4-9459-980b244dec34"

ztaskFindrailroad.Name="Find railroad"

ztaskFindrailroad.Description=[[]]

ztaskFindrailroad.Visible=false

ztaskFindrailroad.Active=false

ztaskFindrailroad.Complete=false

ztaskFindrailroad.CorrectState = "None"

 

ztaskFindAquifinaarea = Wherigo.ZTask(cartTest3)

ztaskFindAquifinaarea.Id="58653b15-4628-4d77-a6ae-f3a95420f32c"

ztaskFindAquifinaarea.Name="Find Aquifina area"

ztaskFindAquifinaarea.Description=[[]]

ztaskFindAquifinaarea.Visible=false

ztaskFindAquifinaarea.Active=false

ztaskFindAquifinaarea.Complete=false

ztaskFindAquifinaarea.CorrectState = "None"

 

ztaskGettotheplankbridge = Wherigo.ZTask(cartTest3)

ztaskGettotheplankbridge.Id="59095708-f9e8-466e-8ef5-0cb5f689ac34"

ztaskGettotheplankbridge.Name="Get to the plank bridge"

ztaskGettotheplankbridge.Description=[[]]

ztaskGettotheplankbridge.Visible=false

ztaskGettotheplankbridge.Active=false

ztaskGettotheplankbridge.Complete=false

ztaskGettotheplankbridge.CorrectState = "None"

 

-- Cartridge Variables --

Random = 0

TimerExpired = false

cartTest3.ZVariables = {Random = 0, TimerExpired = false}

 

-- Builder Variables (to be read by the builder only) --

buildervar = {}

buildervar.Random = {}

buildervar.Random.Id ="763ea73a-b54f-4ac2-bf1c-a5d230b4f292"

buildervar.Random.Name = "Random"

buildervar.Random.Type = "Number"

buildervar.Random.Data=[[0]]

buildervar.Random.Description=[[]]

 

buildervar.TimerExpired = {}

buildervar.TimerExpired.Id ="0dfd5fe7-7c9d-4d09-b9b4-9a6fd9e61da3"

buildervar.TimerExpired.Name = "Timer Expired"

buildervar.TimerExpired.Type = "Flag"

buildervar.TimerExpired.Data=[[False]]

buildervar.TimerExpired.Description=[[]]

 

-- ZTimers --

ztimerStopwatch = Wherigo.ZTimer(cartTest3)

ztimerStopwatch.Id="2d6873df-7ed9-4608-88d7-4768c6b35ac4"

ztimerStopwatch.Name="Stopwatch"

ztimerStopwatch.Description=[[]]

ztimerStopwatch.Visible=true

ztimerStopwatch.Duration=600

ztimerStopwatch.Type="Countdown"

 

-- Inputs --

 

--

-- Events/Conditions/Actions --

--

 

-------------------------------------------------------------------------------

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

-------------------------------------------------------------------------------

 

function zoneParkingarea:OnEnter()

-- #GroupDescription=Enter the parking area --

-- #Comment=Enter the parking area Comment --

ztaskFindtheparkingarea.Complete = true

Wherigo.MessageBox{Text=[[You found the parking area. Now, go to the railroad sign.]],}

zoneRailroadSign.Active = true

ztaskFindrailroad.Active = true

zoneRailroadSign.Visible = true

ztaskFindrailroad.Visible = true

zoneRailroadSign.Visible = true

Random = math.random(0,100)

end

 

function zoneRailroadSign:OnEnter()

-- #GroupDescription=Player enters the railroad zone --

-- #Comment=Player enters the railroad zone Comment --

Wherigo.MessageBox{Text=[[Good. You found the railroad sign.

Now, find the Aquifina rest stop.]],}

ztaskFindrailroad.Complete = true

ztaskFindAquifinaarea.Active = true

zoneAquifinaArea.Active = true

zoneAquifinaArea.Visible = true

ztaskFindAquifinaarea.Visible = true

end

 

function zoneAquifinaArea:OnEnter()

-- #GroupDescription=Enter the Aquifina area --

-- #Comment=Enter the Aquifina area Comment --

ztaskFindAquifinaarea.Complete = true

zonePlankbridge.Active = true

zonePlankbridge.Visible = true

ztaskGettotheplankbridge.Visible = true

ztaskGettotheplankbridge.Active = true

Wherigo.MessageBox{Text=[[Great!

Now, it's a time attack to the plank bridge. You have ten minutes.]],}

end

 

function zoneAquifinaArea:OnExit()

-- #GroupDescription=Exit the Aquifina zone --

-- #Comment=Exit the Aquifina zone Comment --

ztimerStopwatch:Start()

zoneAquifinaArea.Active = false

zoneAquifinaArea.Visible = false

end

 

function ztimerStopwatch:OnTick()

-- #GroupDescription=Timer expires --

-- #Comment=Timer expires Comment --

TimerExpired = true

Wherigo.MessageBox{Text=[[Too late!]],}

ztaskGettotheplankbridge.Complete = false

end

 

function zonePlankbridge:OnEnter()

-- #GroupDescription=Enter the plank bridge --

-- #Comment=Enter the plank bridge Comment --

if ztimerStopwatch.Duration > 0 then

Wherigo.MessageBox{Text=[[Great! Good job.]],}

ztaskGettotheplankbridge.Complete = true

end

end

 

function cartTest3:OnStart()

-- #GroupDescription=Start cartridge --

-- #Comment=Start cartridge Comment --

zoneParkingarea.Active = true

zoneParkingarea.Visible = true

ztaskFindtheparkingarea.Active = true

ztaskFindtheparkingarea.Visible = true

end

 

function zoneRailroadSign:OnExit()

-- #GroupDescription=Exit railroad sign - hide the railroad stuff --

-- #Comment=Exit railroad sign - hide the railroad stuff Comment --

zoneRailroadSign.Visible = false

zoneRailroadSign.Active = false

end

 

function zitemRandom:OnGetRandom()

-- #GroupDescription=Get random number --

-- #Comment=Get random number Comment --

Random = math.random(0,100)

end

 

function zcharacterRandomGuy:OnTalk()

-- #GroupDescription=Talk to random guy --

-- #Comment=Talk to random guy Comment --

Random = math.random(0,100)

if Random >= 50 then

Wherigo.MessageBox{Text=Random .. [[ is a higher number.]],}

else

Wherigo.MessageBox{Text=Random .. [[ is a lower number.]],}

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 cartTest3

Edited by Ranger Fox
Link to comment

Thanks, Ranger Fox, for your informative and helpful write-up. I am sure that others will find this useful.

 

I have a couple of explanations/corrections to add:

 

-- I originally typed this post to display two message boxes, one to show the random number and one to tell if it is a higher or lower number. However, showing two message boxes one after another does not work well. It'll show the boxes, but the first will give way to the next without requiring user input. Instead, we'll create one message box to display and it will say the number AND if it is a higher or lower number.

 

The Wherigo toolset is written with the concept that "time does not stop" in mind. This means that there are no "pause and wait for the user to respond" constructs in the library. (In computer science "speak," all UI elements are non-modal and it is not possible to block the logic flow to wait for input.) What does all this mean? Well, put simply, any MessageBox, GetInput, etc, will replace (or overwrite) any MessageBox, GetInput, etc, that is already being displayed. So placing two MessageBoxes back-to-back will have the side-effect of causing the first one to flash very briefly and then be immediately replaced with the second one.

 

This doesn't mean that it is not possible to display two MessageBoxes (or whatever else) in row, but just that you have to do it in a special way. One way (the hard way) is to use MessageBox callbacks, and only display the second MessageBox once the user has acknowledged the first one. Another way, the easier way, is to use the Wherigo Library "Dialog()" API, which defines a sequence of MessageBoxes to be displayed, one after the other, like you would see in a character dialog (one person talks, then the other, etc). You can find the "Dialog()" API in the Builder at the bottom of the list of actions to select from when you are building the action script for a function.

 

Open your .lua cartridge file in Notepad. First, type the following line at the top of the file:

requires "math"

WARNING: You will have to insert the above statement manually after EVERY TIME you save your cartridge. It keeps losing that statement, which was the cause of my confusion. Odd, but it happens.

 

This is due to the fact that the Builder is very particular about what Lua script it can parse and in what format. And because it is very particular about what it can parse, it is very particular about what it writes out. Essentially, you should not count on it to preserve _any_ changes you make to the script file outside of the Builder, unless those changes are made in very specific areas. One such area is the "Author Directives" at the top of the file. Rather than placing the

require "math"

line at the very top of the file, it should be placed about 6 (or so) lines down, inside the "Author Directives" section of the file. This will cause the Builder to preserve that line and not remove it the next time you edit the file in the Builder.

 

In fact, you should be _very_ careful about any changes you make to the script file outside of the Builder (if you intend to continue to edit the file int he Builder in the future). Not only is it possible to "lose" changes, but it is also possible to "break" the file such that the Builder will not open it any more. The recommendation here is to only edit lines inside the following script blocks: "Author Directives" and "Author Functions". If you edit lines anywhere else you essentially do so at your own risk.

 

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