Jump to content

Detect if another item is at the current zone?


northernpenguin

Recommended Posts

I'm working on a 'game' Wherigo, and I'm wondering if there is an easy way to determine if another object is in the current zone without hard coding the zone itself into the action.

 

I want to have a scenario where two objects cannot be in the same place at the same time, across several different zones. Rather than hard coding everything (and having mountains of repetitive code) I'd like to have a test if the person goes to "place" the object like follows

 

say the player wants to "drop" ObjectB at the zone the player is standing in:

 

if objectA is in the currentZone

show a message "cannot be placed here"

else

move objectB to currentZone

 

Just wondering if I can do this without having to test every zone/object combination each time an object is moved.

Link to comment

It is possible, but not within the Builder. There's a way to retrieve all zones in a cartridge. You could use that in a loop.

 

The following code retrieves all zones and makes them inactive:

local allZones = zcart:GetAllOfType('Zone')
 for _,zone in ipairs(allZones) do
  if zone ~= nil then
 zone.Active = false
  end
 end

 

If you'll notice, it's also possible, then, to return all items or timers in a cartridge for other operations. You could even do a logic test based off the name so that only, say, items starting with "zitemCoin" are manipulated in this way.

Link to comment

Hello,

 

if "in the current zone" means is visible to the player than you can check, if the player sees the object:

 

function isItemVisible(parItem)
 local retValue = false
 for k,v in pairs(Player.GetVisibleObjects(Player)) do
if v == parItem then
  retValue = true
end
 end
 return retValue
end

 

Hope this helps

 

Best regards

Dirk

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