Referring to a scene with a variable

kidbeyond

  • Posts: 89
I know others have posted about this, but I wanted to bump this discussion before the In-App Purchases release...

Right now in Design Mode, there seems to be no way to refer to a scene with a variable -- <"Scene " + SceneNum> --  rather than directly. (Correct me if I'm wrong!)

So if I have a level selector -- with button actors created programmatically (not in Scene Designer), where the user can pick which level they want to play -- I have to hand-specify each scene by name.

But I intend to use IAP for the purchase of new level packs. I don't know how this is being implemented, but I'm assuming that purchasing new levels means new scenes... making it pretty crucial to be able to refer to scenes with a variable.

Any thoughts?

Hectate

  • *
  • Posts: 4643
You're correct that there's proper way to do this on-the-fly using Design Mode alone. However, if you intend to have a consistent naming convention (as your second paragraph seems to indicate) you should be able to use some of the code blocks to assign the scenes to your variables using names and then use regular Design Mode blocks for everything else in the level selection scene. Would you be willing to go that route?
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

coleislazy

  • *
  • Posts: 2607
Actually, I think he's completely correct in this matter: scenes are referred to by their numerical ID only, so there's no real way to have something like:
Code: [Select]
_MyScene = "Level" + levelCounter;

Alexin

  • *
  • Posts: 3130
Code: [Select]
public function getSceneByName(name:String):Scene
{
var scenes:Array = Game.get().scenes;

for each(var scene:Scene in scenes)
{
if(scene.name == name) return scene;
}

return null;
}

Not tested.
"Find the fun"
alexin@stencyl.com

kidbeyond

  • Posts: 89
Thanks for the help... I haven't embedded code or used AS3 before, so please pardon my ignorance when I ask for some further hand-holding.

I'm doing a Mobile Game, so StencylWorks disables Code Mode but allows embedding code in Design Mode.

So, my questions:

1. Can I use Alexin's code above in a code block embedded in Design Mode, or would I need to change it?

2. Once the function returns the scene, how would I switch to that scene? Can I do it in Design Mode, or would I need more embedded Code?

Thanks in advance...

coleislazy

  • *
  • Posts: 2607
I think we were in the Flash mindset, and completely ignored the part where you told us it was a mobile project.

In this case, Alexin's code would not work. There may be a way to do it, but you'd have to use objective-c, which I know almost nothing about. Sorry!

kidbeyond

  • Posts: 89
Gotcha -- thanks. Hopefully there's someone lurking with ObjectiveC-Fu.

Jon

  • *
  • Posts: 17526
So you'd like to get a scene by name and switch to it? I can add a code-only API call for it and consider it for the future as an alternate way to switch in.

Jon

  • *
  • Posts: 17526
I'll send you an e-mail. This will be in 1.4.0.

And you'll do this little trick.

« Last Edit: January 07, 2012, 03:16:36 pm by Jon »

kidbeyond

  • Posts: 89

« Last Edit: January 08, 2012, 09:04:11 am by kidbeyond »

kidbeyond

  • Posts: 89
Worked like a charm. Thanks.