+Beach_hut Posted March 29, 2015 Share Posted March 29, 2015 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? Quote Link to comment
+charlenni Posted March 29, 2015 Share Posted March 29, 2015 (edited) 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 March 29, 2015 by charlenni Quote Link to comment
+Beach_hut Posted March 29, 2015 Author Share Posted March 29, 2015 Brilliant. Thanks Dirk Quote Link to comment
Recommended Posts
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.