Is there an "actor type as text"? (ANSWERED)

docskull

  • Posts: 65
Hello there,

I am not that good at coding and I would like in a scene to create a specific actor type wich name is stored in a text variable.

I can't drag text or any "variable as text" inside the "create (actor type) at  X , Y"  block.

So, is there any way to do it?

« Last Edit: January 12, 2012, 09:15:06 am by docskull »

Alexin

  • *
  • Posts: 3132
Paste the following code in a code block (the new one):
Code: [Select]
getActorTypeByName(_Variable)

Where _Variable is the internal name of a Text Attribute
"Find the fun"
alexin@stencyl.com

docskull

  • Posts: 65
Where is this new Code block you mentioned?

The ones under "Flow - Advanced" won't fit.

Alexin

  • *
  • Posts: 3132
Do you see two or three code blocks? If you can see two only then you must update SW.
"Find the fun"
alexin@stencyl.com

coleislazy

  • *
  • Posts: 2607
You can also do it this way:

Create an Actor Type attribute. I'll call it "MyType".
Put this code in a code block, where _SomeText is your text attribute:
Code: [Select]
_MyType = getActorTypeByName(_SomeText);Then you can drop the "MyType" block into the create block as normal.

docskull

  • Posts: 65
Hey Alexin, I have only two "code" type blocks, but the program says its up to date... (v1.3.4 b413)

Thanks Cole, I will give it a try right now

Alexin

  • *
  • Posts: 3132
Oops! I guess you need the next preview to access the block.

http://community.stencyl.com/index.php/topic,6345.0.html
Code Expression Block.
"Find the fun"
alexin@stencyl.com

docskull

  • Posts: 65
Woot! And also new features. Installing it :P

Thanks my friend!

saulochina

  • Posts: 214
this will work for ios?? how can i set the _Variable or _SomeText?
i have a list with letters that are the names of the actors, i want to go trough the list and set a letter to be _Variable, and then create the named actor. help? :-)
Finding the fun!
Squib Wars. Now complete, and avaible for free on App Store! http://bit.ly/LxJ62L
https://www.facebook.com/twoheadedgames
Twitter: @saulochina
MSN: sauloj.china@hotmail.com

Alexin

  • *
  • Posts: 3132
The code is AS3 so it won't work with iOS.

« Last Edit: January 14, 2012, 11:26:39 am by Alexin »
"Find the fun"
alexin@stencyl.com

saulochina

  • Posts: 214
tks alexin!

anyone knows how to do some similar for ios? i have one behavior to do what i want in design blocks, but have to many blocks, i want to short my behaviors...
Finding the fun!
Squib Wars. Now complete, and avaible for free on App Store! http://bit.ly/LxJ62L
https://www.facebook.com/twoheadedgames
Twitter: @saulochina
MSN: sauloj.china@hotmail.com

BenjoKazooie

  • Posts: 29
I would also like to know how this can be done on iOS. I'm trying to create an Actor of a random Actor Type by picking its name from a text List, but I see no way of deriving an Actor Type from a text string.

Is there an iOS analogue to getActorTypeByName()?

Alexin

  • *
  • Posts: 3132
I really don't know. You're better off asking in the iStencyl Pro board.
"Find the fun"
alexin@stencyl.com

opelman

  • Posts: 7
yes there is an iOS analogue to getActorTypeByName(), it is:
Code: [Select]
[self getActorType:_ActorTypeName]
where _ActorTypeName is the internal name.

The problem I am having is for iOS it wants a number and converting items in a list to a number is not working. The game will compile but crashes... not sure why. (also, the reason I am using "10" in my list is because if you preview the code with an actor type selected you can see that actor types corresponding #. I do not know how SW or the code decides to change an actor type to a number.

opelman

  • Posts: 7
Not what I really wanted to do, and I know there has to be a way to do it in the code but for now I came up with a  work-around. I just made a number attribute and had it set to a random number and then check in a few if statements for that number and create the actor type based on that. With only two actor types its not so bad, but I will have at least a dozen or so different actor types... hopefully someone can figure out the code or SW can update it so that lists work with iOS code.