playMaker

Author Topic: [Solved] INT Switch with 100 options slowing down game... is there a better way?  (Read 3739 times)

createasaurus

  • Full Member
  • ***
  • Posts: 146
I'm making a preschool education game, where the user picks letters, numbers, shapes, and colors.  There are about 100 possibilities.

Right now, I pick a random number 1-100.  Then an I have an Int Switch determine:
If random=1, play audio "one" and put graphic 1 on polygon.
If random=2, play audio "two" and put graphic 2 on polygon.
If random=3, play audio "three" and put graphic 3 on polygon.
etc, ect, ect, ect ... all the way to 100.

I'm having some frame drop issues overall in my game.  I haven't isolated this as the problem, but this is a prime suspect.  So, my question is, is there a simpler, more elegant, less sloppy way to do this?

Thanks!
« Last Edit: June 17, 2014, 01:53:42 PM by createasaurus »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Seems like unless they are running simultaneously then this probably isn't the culprit. How does it work, exactly?

The Profiler would let you track this down pretty quickly.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Is the frame rate drop in the editor or in a standalone build?

JennaReanne

  • Junior Playmaker
  • **
  • Posts: 57
    • Little Worlds Interactive
I would see if you can find some ways to get around using an int switch.  For example, you could use the variable as your sound / image names.  If the player picks "3", you would convert that to a string variable named something like "ImageIDName" and update the graphic to your "ImageIDName" variable (which in this case, would be 3).  I use this method frequently with the "TK 2d Sprite Set Id" action, but I'm sure there are similar options even if you're not using 2D Toolkit.

Martin-Vaupell

  • Junior Playmaker
  • **
  • Posts: 70
  • Creating CarbonDiOxide
    • Evisystems
To get around the switch..

To be honest, I would turn to C# and do a while loop,
Exspecially if i have to loop through more than 5 of the same function.

or better yet, write a
On Case select function, that can autoreplace for each number.

There is a "school" saying for programmers.
If you write the same line twice, with different variables, then you are doing something wrong, or ineffective.

Meaning

If random=1, play audio "one" and put graphic 1 on polygon.
If random=2, play audio "two" and put graphic 2 on polygon.
If random=3, play audio "three" and put graphic 3 on polygon.
etc, ect, ect, ect ... all the way to 100.

It is bad practice.

Instead i would proberly come up with some thing similar to this..
(written in english)

Code: [Select]
E is equal to 0
  For as long as E is less than 100 do the following
    E is equal to E now add 1;
    if random=E, play audio E$, and show graphic E;

    // failsafe exit
    if E is greater than 100 then exit
      break;
  Next


I doubt playMaker has a action for this, but I'm sure one of the very nice
programmers around could write such a specifik action for you to use.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 I bet here your problem is audio, you need to make sure your audio is properly instantiated, cause it can be a killer for performances for Unity to always process your audio file.

 I doubt the playmaker logic is the issue here.

 Can you investigate your audio setup? I would likely suggest all your audio is instantiated and you simply enable disable. Else I totally recommand using an audio framework that will likely better handle complex audio needs ( and performances).

Bye,

 Jean

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Martin does make a good point though, even if it's not the primary cause there is still a lot of waste doing it that way.

Not ideal but better would be getting the random number, converting it to a string, then using Send Event By Name to fire a global event. Kinda sucks because you still need 100 states. More intuitive would be using Build String to compile the names of the audio and graphic plus the random number on the end, then just make sure all your asset names line up to that... Not sure how to make the conversion from a string to an ambiguous asset name though.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 I would suggest "ResourceLoad" action from this forum, but then we're back at square one for audio perfs...

Typically, I guess some audio framework will allow "libraries" and calling a sound by its name, and then building string would start being indeed a very powerful alternatives.

Bye,

 Jean

createasaurus

  • Full Member
  • ***
  • Posts: 146
Thank you everyone!

I have a work around:  The problem was happening specifically when I "created new object."  and the very first state was the Random 100 INT thing.  Now, instead I'm "recycling" my objects by  toggling their visibility and moving them around.   This is working for me.

@Lane re: Profiler and convert to string. Thank you.
@ Alex:The frame rate was in both the editor and standalone build on WiiU hardware.
@JennaReanne re: convert to string.  Thank you.
@ Martin-Vaupell: Thank you.
@ JeanFabre:  re: audio instantiated and ResourceLoad.   Thank you, I will learn more about this next.