#Question about getting custom object data from onPlayerAction selection

1 messages · Page 1 of 1 (latest)

amber dagger
#

When I set up an onPlayerAction(player, action, targets) callback, how would I get the custom object info out of targets when I group select a bunch of objects with custom object info. I assume I should be able to do something along the following:

lua function onPlayerAction(player, action, targets) if action == Player.Action.Select then for i,t in ipairs(targets) broadcastToAll(t.getCustomObject().tostring()) end end

but no dice

faint monolith
#

just so i understand, you want to trigger some function (getting custom object info) when a player (you) selects a bunch of objects? the trigger being selecting?

#

and it looks like you are doing this from the in-game console, not the scripting editor or Atom?

amber dagger
#

yeah, I haven't dug into why but log(foo) doesn't log into the ~ console the way I'd expect in the mod I'm poking

#

specifically I'm just trying to get the mesh, model, collider URLs out of the custom object data of all objects I select, trying to implement a system that auto-loads, maps, and pairs a bunch of custom object figurines to rules data cards automatically

faint monolith
#

well, for one thing, you need to make sure to include a do with the for loop

amber dagger
#

sorry yes the do should be there, I'm not writing this from my dev workstation and pseudocoded from memory

#

I don't have syntax errors on the for or if blocks in the actual implementation but I seem to be misunderstanding what is in targets

#

I assume by doing a for over the pairs i,t in targets I should be able to call t.getCustomObject() and get the custom object but I don't so I'm assuming I don't understand what the t in targets actually is

faint monolith
#

let me check

amber dagger
#

targets should be a table of objects with the key of each element being their guid yes? Perhaps I need to do getObjectFromGUID(t.name).getCustomObject()

faint monolith
#

it doesn't look like it, no

#

when i click and drag to select a bunch of objects, the player action "select" triggers every time a new object is selected. that single object is what is contained in "targets".

#

it doesn't seem to include every object that is currently selected

#

just triggering once per object that gets selected, so the key for each object is 1

#

so i think what you're likely running into is that when you run your function there is no Player.Action.Select action occuring

#

you probably have a bunch of things selected and try to run that function, but i don't think that Player.Action.Select runs on currently selected objects

amber dagger
#

Ah I thought select would work as a group select. Is there a more appropriate action to use with onplayeraction? I guess I could take all objects in the scene but that seems excessive

faint monolith
#

yes, one sec. i can't remember but, yes there is a more appropriate action. its not Player.Action, its something else...

fallen nimbus
#

Player.getSelectedObjects() could help

amber dagger
#

Would player.action.select be appropriate for only calling the getSelectedObjects on a group select

#

Or is there another action I should check for

faint monolith
#

so Player.Action.Select only gets called when you are selecting something with clicking and dragging. Each time a new object is selected, that action is triggered

#

you are looking for a way to loop over objects that are already selected, and Player.getSelectedObjects() is likely the answer

#

but i don't see any documentation on that

amber dagger
#

Yeah I knew that was just the action event type I erroneously assumed onplayeraction would return the selected objects as a table on a group select callback

faint monolith
amber dagger
#

Thanks for the elucidation I'll follow up once I've got it fixed

faint monolith
#

no prob!