YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Accessing the properties of a newly created instance
UbuntuJackson
#1 Posted : Thursday, January 27, 2022 6:31:27 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 1/27/2022(UTC)
Posts: 1
Location: Sweden

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hello, I'm working on a an enemy in a game made in Squirrel. I needs to be solid so I want a solid to spawn at the coordinates of the enemy. That is not the problem though. The problem begins when I want to access that newly created instance's properties (like x and y value) and use that to set it to the enemies x and y values. So how do I access the properties of a newly created instance? If this was python, I would just append the instances to a list. Like: list.append[solid(x, y), solid(x, y), solid(x, y)] and then call the instances x coordinate like list[0].y = enemy.y. However, this is not pyhton. I have read through the documentation but I can't find anything. Am I missing something?
Kelvin
#2 Posted : Saturday, March 19, 2022 12:25:50 PM(UTC)
Rank: Advanced Member

Groups: Registered, Moderator
Joined: 3/26/2015(UTC)
Posts: 66
Man
Location: Georgia

Thanks: 3 times
Was thanked: 0 time(s) in 0 post(s)
You should definitely specify which game/engine you're working with, as that process will be different in all of them. Fortunately, I know which one you're using (mine ;3).

Here's what you gotta do:
Code:

local c = actor[newActor(Thing, x, y)]


This lets you store a direct reference to the newly-created instance, instead of having to write something like `actor[id]` every time. It will still be added to the global actors list as normal, and since you're using a local, the reference will be deleted as soon as you're done working with it automatically, allowing the instance manager to clean it up properly. Now, you can reference its properties like so:

Code:

local c = actor[newActor(Thing, x, y)]
newActor(SolidThing, c.x, c.y)


I hope this helps!
madelyn
#3 Posted : Thursday, August 25, 2022 5:40:56 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/23/2022(UTC)
Posts: 2
Location: Ukarine

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
UbuntuJackson wrote:
Hello, I'm working on a an enemy in a game made in Squirrel. I needs to be solid so I want a solid to spawn at the coordinates of the enemy. That is not the problem though. The problem begins when I want to access that newly created instance's properties (like x and y value) and use that to set it to the enemies x and y values. So how do I access the properties of a newly created instance? If this was python, I would just append the instances to a list. Like: list.append[solid(x, y), solid(x, y), solid(x, y)] and then call the instances x coordinate like list[0].y = enemy.y. However, this is not pyhton. I have read through the documentation but I can't find anything. Am I missing something?

nice post
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.047 seconds.