Jump to content

How to put randomly objects to zones ?


koredump

Recommended Posts

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 !

Link to comment

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

Link to comment

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 by koredump
Link to comment

 

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

Link to comment

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 !

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