+koredump Posted April 12, 2012 Share Posted April 12, 2012 Hi there, I want to hide 4 objects randomly between 10 zones of my cartridge. For this, I want to use an array (coord3 for instance) to store the names of my zones. I need now to set the object.Container and zonePoints I thought about : zitemOne = Wherigo.ZItem{Cartridge=cartName, Container=coord3[random(10)]} zitemOne.ObjectLocation = coord3[random(10)].OriginalPoint For sure it does not work as coord3[random(10)] is a string and not an object. What should I do ? Thanks in advance ! Quote Link to comment
matejcik Posted April 12, 2012 Share Posted April 12, 2012 first, create the items regularly without setting Container second, as long as you're in custom Lua anyway, don't put names of zones in the array, put the zones themselves! i.e. coord3 = {zoneDoorway, zoneLivingroom, zoneDarkforest (......) } no strings, no quotes, direct object references third, use items' MoveTo method: zitemOne:MoveTo(coord3[math.random(10)]) this sets the Container and assigns the ObjectLocation in one fell swoop and you don't have to do it manually fourth, if you don't want to use the same zone twice, don't forget to remove it: r = math.random(#coord3) -- pick a random number from 1 to current length of coord3 z = table.remove(coord3, r) -- remove the element and put it into z zitemOne:MoveTo(z) -- move item to zone z Quote Link to comment
+koredump Posted April 13, 2012 Author Share Posted April 13, 2012 (edited) first, create the items regularly without setting Container second, as long as you're in custom Lua anyway, don't put names of zones in the array, put the zones themselves! i.e. coord3 = {zoneDoorway, zoneLivingroom, zoneDarkforest (......) } no strings, no quotes, direct object references third, use items' MoveTo method: zitemOne:MoveTo(coord3[math.random(10)]) this sets the Container and assigns the ObjectLocation in one fell swoop and you don't have to do it manually fourth, if you don't want to use the same zone twice, don't forget to remove it: r = math.random(#coord3) -- pick a random number from 1 to current length of coord3 z = table.remove(coord3, r) -- remove the element and put it into z zitemOne:MoveTo(z) -- move item to zone z Brilliant, thanks, even more that I expected. Many many thanks... I just have to set the onEnter functions now. Great :-) Edited April 13, 2012 by koredump Quote Link to comment
+koredump Posted April 13, 2012 Author Share Posted April 13, 2012 Brilliant, thanks, even more that I expected. Many many thanks... I just have to set the onEnter functions now. Great :-) By the way, I would need your help again please... What's wrong with this ? n = table.remove(coord3, math.random(#coord3)) function n:OnEnter() -- #GroupDescription=Script -- -- #Comment=Script Comment -- Wherigo.MessageBox{Text="Dommage, ce n'est pas la !", Media=zmediatresorVide, Callback=cartLuneville.MsgBoxCBFuncs.MsgBoxCB1} n.Active = false end The emulator crashes. Thanks in advance !! Quote Link to comment
+koredump Posted April 13, 2012 Author Share Posted April 13, 2012 Nothing wrong, just a badcartridge name... Sorry, I need to go to sleep !!! Everything seems to work almost fine through the emulator, just issues with the inventory... Thanks again ! Quote Link to comment
+koredump Posted April 14, 2012 Author Share Posted April 14, 2012 In fact it does not work through the emulator. for z = 1,6 do i = table.remove(coord3, math.random(#coord3)) function i:OnEnter() Wherigo.MessageBox{Text="Dommage, ce n'est pas la !", Media=zmediatresorVide, Callback=cartLuneRandom.MsgBoxCBFuncs.MsgBoxCB1} i.Active = false i.visible = false end end I get the message but the zones are still active and visible. Is something wrong with the code or the emulators is not specific enough ? Thanks ! Quote Link to comment
matejcik Posted April 15, 2012 Share Posted April 15, 2012 "i" is not what you think in the function. try using "self" instead: self.Active = false; (when you set a zone to inactive, you don't need to set it invisible, it basically drops from the radar and won't show ever again, unless you set it back to active) Quote Link to comment
+koredump Posted April 15, 2012 Author Share Posted April 15, 2012 Many thanks... it works fine now. I should be able to publish it quite soon. 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.