Jump to content

Urwigo Lua Coding


drobare

Recommended Posts

Does anyone have any experience coding Lua in the URWIGO software? I've been trying to do some tests on a player containing an item (Knife) and every variation I try seems to fail. Here is the code that I expected to work:

 

local c = {}

table.insert(c,"Use Pen")

table.insert(c,"Use Pick")

if Player:Contains(zitemKnife) then

table.insert(c,"Use Knife")

end

print(c[1])

print(c[2])

print(c[3])

 

The item is a "Knife" and is most definitely on the player. I can get the Pen and the Pick into the table but the Player:Contains function fails to recognize the Knife. If I misspell the function it causes an exception so I know that the "Player:Contains" is correct. Urwigo is storing the Knife item in some way that I can't get it to recognize.

 

Anybody been successful on their Lua within URWIGO?

 

Thanks.

 

Drobare

Link to comment

I suspect the problem is the naming of items. By your mentioning zitemKnife that is how the Groundspeak builder typically names items I believe. I don't know how URWIGO does it, but in URWIGO it has an item nameand an item identifier. The identifier by default is blank and shows up as automatic in the UI field (i.e. it has URWIGO generate an identifier for it).

 

What I always do for cartridges I am doing LUA coding on, is put my own identifier in that field. That way I can guarantee that the identifier URWIGO is using is the same I refer to it as in LUA. It's a pain to set that everywhere (I do it on items, zones, characters, etc.) but it's the safest way and has fixed many problems for me (especially when doing what you are, putting items in an array)

 

Does anyone have any experience coding Lua in the URWIGO software? I've been trying to do some tests on a player containing an item (Knife) and every variation I try seems to fail. Here is the code that I expected to work:

 

local c = {}

table.insert(c,"Use Pen")

table.insert(c,"Use Pick")

if Player:Contains(zitemKnife) then

table.insert(c,"Use Knife")

end

print(c[1])

print(c[2])

print(c[3])

 

The item is a "Knife" and is most definitely on the player. I can get the Pen and the Pick into the table but the Player:Contains function fails to recognize the Knife. If I misspell the function it causes an exception so I know that the "Player:Contains" is correct. Urwigo is storing the Knife item in some way that I can't get it to recognize.

 

Anybody been successful on their Lua within URWIGO?

 

Thanks.

 

Drobare

Link to comment

Excellent. Thanks a lot! That worked. Putting unique IDs in allows me to access items. I can now make a table (array) of items that are on the player at any point in time. My goal is to make a multiple choice input out of this information. Any ideas on the code to create a custom multiple choice input using this table?

 

Also, (and this shows my extreme ignorance even though I have a programming background), after I build a Wherigo cartridge is there a way to examine all the Lua code that makes it work? I'm guessing the entire cartridge is built in Lua. The Urwigo data file that is created during construction is a slightly-nested XML file and doesn't give any clue into the coding.

 

I suspect the problem is the naming of items. By your mentioning zitemKnife that is how the Groundspeak builder typically names items I believe. I don't know how URWIGO does it, but in URWIGO it has an item nameand an item identifier. The identifier by default is blank and shows up as automatic in the UI field (i.e. it has URWIGO generate an identifier for it).

 

What I always do for cartridges I am doing LUA coding on, is put my own identifier in that field. That way I can guarantee that the identifier URWIGO is using is the same I refer to it as in LUA. It's a pain to set that everywhere (I do it on items, zones, characters, etc.) but it's the safest way and has fixed many problems for me (especially when doing what you are, putting items in an array)

 

Link to comment

Last night I finally figured out my Lua coding in Urwigo issue and I wanted to share it with others who are also a little bit new to building their own Wherigo's. I am making a cartridge where a bunch of items get moved to the Player but I only want the Player to be able to use items in their inventory on the other items which will not be moved to the inventory.

 

The Entire Problem I was trying to solve: I wanted to make custom on-the-fly inputs of choices depending on items that are on the Player. While it is true that you can make a command and set command targets of another item it immediately becomes a two-way command. The command is available from the item where you write the command but also from the item that receives the command. (I tried tricks of making one not visible and other elaborate schemes but the software is too smart for this) I found I was getting extra button clicks coming from the destination object and I didn't like the way it played. I abandoned the idea of using command targets and set targets all back to "none". Basically I knew that I needed to make the input choices every time of items currently on the Player. I also knew that it would have to be done with some Lua coding.

 

I scanned tons of posts on this board to get me part way there. There is a Lua function Player:Contains() that you can use to check if the Player holds an item. You have to create unique item ID's and use these to see if Player actually holds the item. I made ID's for all of my items and eventually for the input also. With Lua you can build what Lua calls a table (actually an array) and assign it to the Input choices. The part I couldn't figure out after awhile was "How do I assign the table after I make it to the choices?".

 

The answer was incredibly simple, but I didn't understand how to get into the Lua code. It's simple. A package you store out of the Urwigo software in a .GWZ file is actually a .ZIP file. Rename the extension to .ZIP and then extract the package including the Lua code. (Windows XP complained about extracting the .ZIP file for some reason so I used 7-zip, an available .ZIP extractor.) I made a test cartridge where all I did is make an Input and saved it out. I unzipped it and voila, I had the code. The unique ID I used for the Input is actually used as the name of the Input object, so you just assign the table to this object's member called "Choices" and you have made your own Input on the fly. My id for the input is "iinput".

 

I think for my purposes I will make multiple Inputs, one for each item not on the Player, and run the code when the person playing chooses one of these items in the zone to interact with. Because normally in game play a person is going to look at something in the zone, and then decide at that moment how to interact with it using items in their inventory.

 

I'm posting the code from my Urwigo and the Lua code I found when I saved out my test cartridge as a .GWZ and extracted. I hope this helps others out there like me that are somewhat new at this.

 

As a final note, the Urwigo builder complained when I made choices in the Input that didn't line up with the event handler for that Input. So I put all possible choices in the Input of what the player can carry to begin with and on startup I run the code so that the player only originally has his "Trusty Pocket Knife".

post-2673526-064310700 1388921198_thumb.jpg

post-2673526-044562000 1388921207_thumb.jpg

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...