It looks like you're new here. If you want to get involved, click one of these buttons!
I’m trying to make a function for helping me streamline entity creation::
function makeAThing(name, modelString, positionVec3, rotationVec3, scaleVec3)
local newEntity = scene:entity()
newEntity.name = name or "entityMadeAt"..tostring(os.time())
newEntity.position = positionVec3 or newEntity.position
newEntity.eulerAngles = rotationVec3 or newEntity.eulerAngles
newEntity.scale = scaleVec3 or newEntity.scale
newEntity.modelString = modelString
--> doesn't work:
newEntity.model = craft.model(asset[modelString])
newEntity.name = name
return newEntity
end
I’ve tried every combination I can think of, including using the ..
operator using bracket notation.
I have also searched the forum, and the reference, and I’ve found lots of stuff about how to save things by appending strings to asset
, but that format doesn’t seem to work in reverse.
Either there’s nothing documenting loading things, or I’ve floundered in finding the documentation, or, I guess, it might not be possible with the new asset system.
Can it be done?
Comments
Is this kind of what you’re after.
Kinda like:
~~~
pics = {}
path = asset.documents.Dropbox
For lp =1, #Objects do
pics[lp] = readImage(Objects[lp])
end
Objects = {
image1,
Image2,
Image3
}
~~~
Please ignore poor formatting and incomplete code , just trying to illustrate the loading method I use.
@dave1707 I don’t think so.
I want to be able to pass a string to a function and have it use that string to attach a model to an entity.
Here’s the function I pasted above, but pared down to just that functionality:
@Bri_G for saving or for loading?
Sample code?
This works if you pass the whole name. Create a table with the full names of what you want and pass a selection.
Or this.
I think you have to use three ` not three ~
@dave1707 I don’t think
craft.model(name)
works in any but very specific conditions, and in the example wherexx(name)
has a hard-coded path to a specific asset pack, that’s the exact thing I am trying to get around having to do.It think I’ve got this now, though. The breakthrough was that, for anything in an asset pack, the pack has to be accessed by brackets too, as in:
I am a bit abashed to admit this, but the frustrating thing was that once I figured this out I looked back through my code and found a place where I’d cut-and-pasted code from the 3D Asset Viewer that does this exact thing.
[original post was written on iPhone, this one was copied and pasted here on an iPad. ]
I was looking at the touch demo you gave me and found that it’s possible to do use string concatenation also because
asset
returns a string for however deep you go.