Jump to content

Choosing three from eight in Urwigo - how?


Beach_hut

Recommended Posts

OK, I'm building a Wherigo in Urwigo and want to create a scenario where, when a player enters a zone, a randomly chosen three characters out of a prescribed list of eight become visible. (they're all going to reside within that zone permanently so switching the visibility on and off is the simple approach)

What's the cleanest, least code-heavy way of approaching that?

Link to comment

The best would be to create a Lua script, which is doing the following (pseudo code):

 

Create a table
Insert all 8 characters in the table
Do 3 times
 Select a random entry in the character table
 Set selected character visible
 Remove character from table
end

This could look in Lua like (when zc1...zc8 the ZCharacter objects):

 

function ActivateCharacters()
 -- Create table and insert all 8 characters
 local characters = {zc1, zc2, zc3, zc4, zc5, zc6, zc7, zc8}
 -- Init random generator
 math.randomseed(os.time())
 -- Do 3 times
 for i = 1, 3 do
   -- Create random number
   next = math.random(1, #characters)
   -- Remove selected character from table
   local character = table.remove(characters, next)
   -- Set character visible
   character.Visible = true
 end
end

Be carefull to set the field "Identifier" of the characters in Urwigo to "zc1", "zc2" and so on.

 

Put the above Lua code into the "Lua user functions". Now call from Urwigo the "Lua User Code" by "ActivateCharacters()". That's all :)

 

Best regards,

Dirk (Charlenni)

Edited by charlenni
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...