How do I call a function after "on created"

Get help using Construct 2

Post » Wed Sep 24, 2014 3:05 pm

First, thank you to everyone who has been answering all of my newbie questions.

Now I'm floundering on program flow.

I have something that looks like this

Code: Select all
On Player Created
-> configurebays()

On configurebays()
-> Spawn gun at Player Image Point X


However, it looks like on player created is called before the object is actually created (???) so the guns never spawn. If I add a button and call configurebays() after the game is loaded it works fine.


I also tried

On LayoutStart
-> Spawn Player
-> configurebays()

but again the guns would not spawn.

So I'm tripping over this issue. I don't have access to my files at the moment but can post the capx or screenshots later (screens might be better)


Second issue I'm battling is sprite vs family instances

On Layout Start
-> create demogun
-> demofamily do something

won't work work, but

On Layout Start
-> create demogun
On Layout Start
-> demofamily do something

does work. (?)
Developing Surolace, the survival role playing space game.

surolace-survival-role-playing-space-game_t116953
B
14
S
4
Posts: 303
Reputation: 1,730

Post » Wed Sep 24, 2014 4:17 pm

your player is probably on the layout at the start of the layout, right?

try something like this

on start of layout > player.destroy
wait 0.5s
System > create player

On create player > do what you want

About spawning guns, maybe you should read about containers on the manual / tutorial section.
B
33
S
5
G
1
Posts: 163
Reputation: 2,698

Post » Wed Sep 24, 2014 4:24 pm

Hi Scofano, I can not use containers because the weapons are dynamic (a player sprite can have any combination of guns on available image points, or no guns at all), unless I misunderstood containers.

The sprite is not on the layout, it is created with a

on layout start -> create playersprite
Developing Surolace, the survival role playing space game.

surolace-survival-role-playing-space-game_t116953
B
14
S
4
Posts: 303
Reputation: 1,730

Post » Wed Sep 24, 2014 4:31 pm

I think it should be. At least on the margin space, outside the layout. Whenever I try to spawn or create something that is not on (any) layout, browser sends me an error.
B
33
S
5
G
1
Posts: 163
Reputation: 2,698

Post » Wed Sep 24, 2014 4:41 pm

heh, I just had a thread about this yesterday. I moved everything out of the margin and into a separate layout for loading that works MUCH better than putting it into the margin, but there is some execution flow that I'm not understanding. I'll upload something soon
Developing Surolace, the survival role playing space game.

surolace-survival-role-playing-space-game_t116953
B
14
S
4
Posts: 303
Reputation: 1,730

Post » Wed Sep 24, 2014 4:44 pm

I believe in you but it makes no sense to me. :P
How being on a different "library loader layout" is better than being at the same layout but just on a negative position? :shock:
Can you share the link of the thread? Im curious.
B
33
S
5
G
1
Posts: 163
Reputation: 2,698

Post » Wed Sep 24, 2014 4:52 pm

All relevent code is in the file "pcturrents", it's sort of a mess because I've been fussing with it trying to get it to work.

edit: Link to thread about resource loading. The turrets work fine if the player sprite is already on the layout, but I need to spawn it dynamically because the player will be able to choose from various ships.

how-do-i-load-game-resources_t116107


Edit again:

POC, the turrets will work when called later on. If you start the game with F4 choose campaign, swipe to move over the moon, click the commlink, then choose plunder planet, I stuck a call to it there, and it works fine. For some reason, no matter what I do, I can't insert code to run right after the object is created. Help! :)
You do not have the required permissions to view the files attached to this post.
Developing Surolace, the survival role playing space game.

surolace-survival-role-playing-space-game_t116953
B
14
S
4
Posts: 303
Reputation: 1,730

Post » Wed Sep 24, 2014 7:32 pm

Bump.

I'm positive there's a simple solution or a simple mistake I'm making. Proverbial missing semicolon?
Developing Surolace, the survival role playing space game.

surolace-survival-role-playing-space-game_t116953
B
14
S
4
Posts: 303
Reputation: 1,730

Post » Wed Sep 24, 2014 10:12 pm

You can pass the ship UID to the function and then pick the ship by UID in the function.

Newly created objects aren't properly created until the next top-level eventso it seems the ship doesn't exist yet in the "configurebays" function but you can pick it by UID.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,670

Post » Wed Sep 24, 2014 10:27 pm

That explains EVERYTHING, thank you so much. That just answered other questions I had and didn't even know I had.

A very easy way to think about it is that scope applies to created instances, but really, rendering does not happen until after event execution so any scope above it does not know the new sprite exists.
Developing Surolace, the survival role playing space game.

surolace-survival-role-playing-space-game_t116953
B
14
S
4
Posts: 303
Reputation: 1,730

Next

Return to How do I....?

Who is online

Users browsing this forum: brunopalermo and 10 guests