No no no. This is your code:
function init(self)
local p = go.get_position()
go.set_position(vmath.vector3(500, 170, 10))
factory.create("factory#snigel_factory", p())
end
Letâs break it down line by line:
local p = go.get_position()
The above line gets the position of the current game object and stores it in the variable p
. The position is of type vector3.
go.set_position(vmath.vector3(500, 170, 10))
This line sets the position of the current game object to 500, 170, 10.
factory.create("factory#snigel_factory", p())
This line creates a game object from the factory with id snigel_factory
on the game object with id factory
. The second argument should be a vector3 position.
But what actually happens is that you use the variable p
from the first line as if it was a function (you âcallâ the function by the () immediately after it). The variable p
contains a value of type vector3. It is not a function and you canât call it.
If you want to spawn a game object from the snigel_factory
on position 500,170,10 you should do as in my first post:
function init(self)
factory.create("factory#snigel_factory", vmath.vector3(500, 170, 10))
end
Ok, will try soon thank you!
Why donât you save files?
Still doesnât work
You need to provide more information. For instance just zip your project and upload it here.
But here is an example I wrote for someone else, but maybe it can help you too.
In it you can see how to randomly spawn a game object. Please check how the different parts are setup as thatâs probably where something is wrong for you.
example.zip (3.1 KB)
function init(self)
factory.create(âfactory#snigel_factoryâ, vmath.vector3(500, 170, 10))
end
here is the code, it doesnt work
The same code works for me. Have you added the script to the game?
Depending on your render script the z value (the 10) could be outside of your frustrum. Set it to 0 to be sure itâs actually being rendered.
Thereâs more stuff going on - looking at the bottom of the screenshot (why are you taking pictures of your screen, @daniel06061811, and not simply screenshots?) it looks like the sprite buffer is full and the maximum number of collisions is being reached.
I think it would be best if @daniel06061811 took a step back for a bit and had a look at some of the tutorials and examples before trying to make something from scratch. Thatâs just my suggestion.
Yea sure but I the code is right so I am just trying to figure out whatâs wrong. I wasnât taking screenshot because I was writing to you on the phone.
Right, that line of code is correct now. But it took a lot of time for many people to get you there. I think itâs great that youâre learning and people here are super helpful, but I would really recommend you try and learn how to properly ask a question. It will be really useful, because:
a) It will make it easier for the helpers to understand what you need help with, giving you a better answer; and
b) You might often end up answering the question yourself while preparing the question.
Take a look at these examples:
- Creating tilemaps through factories does not update collision for programmatically changed tiles
- Change camera pivot point
They are great because they tell a story, and include pictures and detailed descriptions. You should describe your project, what you want to happen, what actually happens, what you have done so far, what you think might be wrong, etc. Include screenshots and code snippets. If that feels like too much effort, then think about the people that have to answer your question by guessing about all of those points.
My suggestion would be to take some time to write out a proper question about your situation, because the people helping you here are still guessing about your issues.
Ok, great!
Thank you for the links and advices!
@Alex_8BitSkull is right. Weâd love to help you but we donât have enough information. You need to provide more information about your problem because the line of code to spawn game objects is correct. The problem is elsewhere in your project.
Doesnât your laptop have an internet connection? Why do you type your questions on your phone and not on the laptop? Itâs easier to write a good question if you do it on your laptop and you will be able to provide proper screenshots from the laptop.