[SOLVED] multiple clickable component
[SOLVED] multiple clickable component
Hi everyone,
trying to add 2 "alcove"s to a single object, it works for surfaces but when i put "clickable" components all of them work but they put items in first surface ignoring others.
Any way to tell a clickable component to be linked to a specific surface?
TY
trying to add 2 "alcove"s to a single object, it works for surfaces but when i put "clickable" components all of them work but they put items in first surface ignoring others.
Any way to tell a clickable component to be linked to a specific surface?
TY
Last edited by Granamir on Tue May 26, 2015 11:51 am, edited 1 time in total.
Re: multiple clickable component
no, but you can use onAcceptItem to force clicks to go to the correct surface, as it will try the next surface if one fails. example:
Code: Select all
{
class = "Surface",
name = "leftSurface",
offset = vec(0.6,0.04105,0),
size = vec(0.5,1.2),
onAcceptItem = function(self,item)
local surf = GameMode.tempSurface
GameMode.tempSurface = nil
if surf == 2 then return false end
end,
},
{
class = "Surface",
name = "rightSurface",
offset = vec(-0.7,0.04105,-0.2),
size = vec(0.5,1.2),
onAcceptItem = function(self,item)
local surf = GameMode.tempSurface
GameMode.tempSurface = nil
if surf == 1 then return false end
end,
},
{
class = "Clickable",
name = "leftClick",
offset = vec(0.6,0.3,0),
size = vec(0.5, 0.6, 1.2),
maxDistance = 1,
onClick = function(self)
if getMouseItem() then GameMode.tempSurface = 1 end
end,
},
{
class = "Clickable",
name = "rightClick",
offset = vec(-0.7,0.3,-0.2),
size = vec(0.5, 0.6, 1.2),
maxDistance = 1,
maxDistance = 1,
onClick = function(self)
if getMouseItem() then GameMode.tempSurface = 2 end
end,
},Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: multiple clickable component
Yes it works perfectly.
As always thank you minmay.
...and is there a way to put an item in alcove in a specific orientation? I need to put books as they are in bookshelfs not on ground.
...and another question: is there a way to rotate items in surfaces accordingly with object (containing surfaces) rotation?
As always thank you minmay.
...and is there a way to put an item in alcove in a specific orientation? I need to put books as they are in bookshelfs not on ground.
...and another question: is there a way to rotate items in surfaces accordingly with object (containing surfaces) rotation?
- JohnWordsworth
- Posts: 1397
- Joined: Fri Sep 14, 2012 4:19 pm
- Location: Devon, United Kingdom
- Contact:
Re: [SOLVED] multiple clickable component
That's neat Minmay. I will be using that for the book shelves and wooden shelves I recently made!
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
Re: multiple clickable component
Well, first of all, the surface's "rotation" field is applied to any items inside, and not the surface box itself. So this is the typical way to accomplish this. (Example: the beach puzzle statue in the standard assets...it's a socket rather than a surface but the same principle applies). If you need to change the rotation or position of a specific item inside a surface, you can just do so the same way you would if it was on the floor, with setWorldPosition() and setWorldRotation() and setWorldRotationAngles() and so on, because it's still a complete object, the surface just has a reference to it and you have to be on the surface's square to pick it up.Granamir wrote:Yes it works perfectly.
As always thank you minmay.
...and is there a way to put an item in alcove in a specific orientation? I need to put books as they are in bookshelfs not on ground.
...and another question: is there a way to rotate items in surfaces accordingly with object (containing surfaces) rotation?
If you destroy an item in a surface or remove it from the map, however, you also need to destroy the SurfaceComponent, otherwise saving will save an unresolvable item reference and produce a save game that will crash when it's loaded.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: [SOLVED] multiple clickable component
Just now i recognize those was 2 aspect of same question.
Thank you.
So solving 1st problem is easy now, but still don't know how to solve 2nd.
In my 1st question i just need to rotate item (book) because surface is stationary.
My 2nd question it's quite harder to solve because surface is rotating and not around his Y axis but around object (bookshelf) Y axis, this mean surface portray a circle and items inside would do the same (or at least i'd like to). So delta angle for items is the same i use for rotating bookshelf, but have absolutely no idea how to manage setSubtileOffset() for those items (to make them portray a circle).
Thank you.
So solving 1st problem is easy now, but still don't know how to solve 2nd.
In my 1st question i just need to rotate item (book) because surface is stationary.
My 2nd question it's quite harder to solve because surface is rotating and not around his Y axis but around object (bookshelf) Y axis, this mean surface portray a circle and items inside would do the same (or at least i'd like to). So delta angle for items is the same i use for rotating bookshelf, but have absolutely no idea how to manage setSubtileOffset() for those items (to make them portray a circle).
Re: [SOLVED] multiple clickable component
You would use the same method and the same math that you use for rotating the bookshelf...
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: [SOLVED] multiple clickable component
Well not really same math, btw i think i got it, now i need programming skills.
As far as i know i need SurfaceComponent:contents() to retrieve items in my surface, but i do not understand what i get from it. Seems i get: 1) a function, but don't know what function and what can i use it for since i get only it's adress; 2) object with surface (that i already had because i called contents() on it, so don't know what to do with it); 3) number 0.
Can u explain me how to use it please? Or what i have to use to retrieve items on surface?
Once i'm going to have a fully functional function is there a way to put it in defineObject{} so that it make automatically calculations when i make object rotate (with an in game function)?
TY
As far as i know i need SurfaceComponent:contents() to retrieve items in my surface, but i do not understand what i get from it. Seems i get: 1) a function, but don't know what function and what can i use it for since i get only it's adress; 2) object with surface (that i already had because i called contents() on it, so don't know what to do with it); 3) number 0.
Can u explain me how to use it please? Or what i have to use to retrieve items on surface?
Once i'm going to have a fully functional function is there a way to put it in defineObject{} so that it make automatically calculations when i make object rotate (with an in game function)?
TY
Re: [SOLVED] multiple clickable component
SurfaceComponent:contents() returns an iterator that returns a numeric index and the item. You use it like this:
Code: Select all
for _,i in alcove_1.surface:contents() do
if i.go.name == "tome_earth" then print("this is a tome of earth") end
endGrimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: [SOLVED] multiple clickable component
Thank you very much, i think i got it. (btw is _ a variable?)
Ok now that i'm starting to figure my code i got another question (if u don't mind): is there a way to put my code in defineObject{} so that it make automatically calculations for items in surface when i make mother object rotate (with an in game function)? A hook or something that calls my function when object is drawed, updated, moved, refreshed, or whatever?
TY
Ok now that i'm starting to figure my code i got another question (if u don't mind): is there a way to put my code in defineObject{} so that it make automatically calculations for items in surface when i make mother object rotate (with an in game function)? A hook or something that calls my function when object is drawed, updated, moved, refreshed, or whatever?
TY