[HELP PLEASE] Spawning an Actor

Adder

  • Posts: 37
I'm trying to spawn a player actor at a random location in the next scene. However, the next scene refuses to load due to this.
The code I'm using to load the next scene is attached. Please inform me as to what I am doing wrong.
Hiss hiss

vicevicebingo

  • Posts: 80
I don't get switch scene problem from your code.
Actor 'enemy' appears in layer name object
but not layer name Layer 0 though.

Adder

  • Posts: 37
I don't get switch scene problem from your code.
Actor 'enemy' appears in layer name object
but not layer name Layer 0 though.
I see that you're not using a random spawn location and yours is working, so maybe it's the random spawning that causes my problem. Thanks for your help.
Hiss hiss

Bombini

  • *
  • Posts: 1400
I'm trying to spawn a player actor at a random location in the next scene. However, the next scene refuses to load due to this.
The code I'm using to load the next scene is attached. Please inform me as to what I am doing wrong.

I would simply put the creation actor code into the next scene.

JeffreyDriver

  • Posts: 2262
Enable the log viewer so you can see what errors, if any, are generated when you try to switch scene.

Adder

  • Posts: 37
I'm trying to spawn a player actor at a random location in the next scene. However, the next scene refuses to load due to this.
The code I'm using to load the next scene is attached. Please inform me as to what I am doing wrong.

I would simply put the creation actor code into the next scene.
I cant do that because it would mean that whenever that scene is returned to, the player ship would be in a different spot. I'm trying to make the initial position when starting a new game random, but keep current position for if the player is (for example) returning from a planet's surface (which is a separate scene)
Hiss hiss

Adder

  • Posts: 37
Enable the log viewer so you can see what errors, if any, are generated when you try to switch scene.
When I click "New Game", this code pops up.
Code: [Select]
Engine.hx:1732: Switching to scene 3 Deep Space.js:39610:203
Engine.hx:1991: Layer ID: 1 does not exist Deep Space.js:39610:203
Engine.hx:1992: Putting actor inside default group Deep Space.js:39610:203
BehaviorManager.hx:135: Warning: Behavior does not exist - Spawn Deep Space.js:39610:203
uncaught exception: Error: Cannot cast null to {
__name__ : [com,stencyl,models,scene,Layer]
}

Here is the "block code" I am using:

"Spawn" Scene behaviour


Player's "when created" event


New Game's "when clicked" event

« Last Edit: October 24, 2018, 06:08:42 pm by Adder »
Hiss hiss

Crovaxus17

  • Posts: 76
Here is a suggestion:
If I understand you correctly, you want the player to start the game in a random spot when the game is first loaded, but then spawn in regular predictable locations (like depending on what direction or previous location the player entered the scene from or something) all other times, right? Well, you could use a global boolean variable, like "firstTime" or something that starts out true. When the game first loads, if firstTime = T, move the player to a random spot and set firstTime to F. If it really is just the randomizing code in the creation block that is causing the error, this would work around that. And actually, you could probably use a similar technique if there are other times than the beginning of the game that you want the player's spawn location to be random: whenever you want that to happen, you just set the global variable to true before switching to the next scene. Does that help?

« Last Edit: October 26, 2018, 05:24:30 am by Crovaxus17 »