### Creating Enemy + HP Bar - > on kill next enemy

#### Exportforce

• Posts: 90
Hello,

I am already quite far with learning on Stencyl, thanks to this cool community
My first game already works better than I could have thought and at the moment no problems on that one.
But I already have a second little game in my head to learn stencyl better to understand and for that I have a static little square of pure evilness, which has to be killed, else we will all gonna die.

So as I can't find a way to create 3 dimensional arrays I created myself 2 lists.

List 1: Enemies
0. Square
1. Evil Square

List 2: HP Values
0. 15
1. 150
(This way I can add as many lists and just make a random roll to select one number and use it for all lists and have a full sprectrum of values with one roll at hand.

I also already drew myself a most beautiful rectangle which I can fill.
Now I have the following problem:

How can I now say: Get yourself a new enemy and draw actor X, give him values of those items from these lists.
The super sexy rectangle gets filled to 100% and when the player attacks the super evil square the alloted damage will deduct the temporarly set HP and reflect that by the rectangle. If enemy dead -> everything starts from above

I looked through that now around 2 hours and can't find myself a way to do that...
Btw. This is my sexy rectangle. placement for the super evil square doesn't matter, as I can move it any time.

#### yoplalala

• Posts: 1611
Try using this http://www.stencyl.com/help/view/set-get-attributes-remotely/ or actor values .
When you create your ennemy just change his hp.  Create an actor attribute like Ennemy to the last created actor.
And for the rectangle will depend on the attribute / actor value  of the Ennemy.

#### Exportforce

• Posts: 90
I don't use behaviours.
I am now this far, finding out that "Actor Type" is not a type but the actor itself... -.-

http://i.imgur.com/pVuIBFK.png
But when I try to preview that scene it prompts me an error for a bad zero

#### yoplalala

• Posts: 1611
What do you mean actor ty pe is not a type ?
Actor type is an actor type , for example Ball.
An actor is an instance of the actor type, for example Ball_1, Ball_4.

Try to pu only drawing events in the draw section. Drawing depends on the capacity of your computer and the ressource your game consumes, so it can change over time. usually it loops 60 times a second,  but it can be less.

You can put your if in in a always event or better even in a event you trigger ( but as you have just started, it 's okay to put this in a always event).

To have a rectangle that is filled or not depending on the hp.  you can change the fill rectange width to current-hp/max_hp * size of the normal rectangle (101).

#### Exportforce

• Posts: 90
Well, when I want to add an actor, I look for "create actor" a type is a version of something, like number is a type of valuestorage for attributes. Easy to misunderstand.

I now moved the actor creation part into an "updated" as "always" and get the very same error about a zero.

#### yoplalala

• Posts: 1611
I 'm not sure you can put your stroke thickness to 0. That must the error. Put it to 1 or 2

#### Exportforce

• Posts: 90
Nope, that is fully ok and intended to be zero

edit: https://www.dropbox.com/s/vdaub0gr64mg90f/RPG%20Test.7z?dl=0
Thats the project. I really can't find any idea where an error could be. I only can think of anything with the lists,  as something might work differently then I think.

« Last Edit: July 17, 2015, 04:53:14 am by Exportforce »

#### yoplalala

• Posts: 1611
It works on my side, it doesn't tell me about a zero.

But I see there is a problem, which must appear not eveytime. Maybe this is it.

it must be set current id to random number between 0 and (number of list - 1).
Because if you have list of one, and the random number is 1 , there isn't an item 1.

#### Exportforce

• Posts: 90
Okay, I thought it works like every randomizer in terms of rand(0,5) to get a random from 0 to 5. But just tried with a -1, but doesn't work too... always getting the very same error...

Quote
TypeError: Error #1009: Der Zugriff auf eine Eigenschaft oder eine Methode eines null-Objektverweises ist nicht mÃ¶glich.
at MethodInfo-5206()[Source/scripts/SceneEvents_0.hx:130]
at com.stencyl::Engine/update()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:2382]
at com.stencyl::Engine/postUpdate()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:2584]
at com.stencyl::Engine/onUpdate()[C:/Program Files (x86)/Stencyl/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:2577]

#### yoplalala

• Posts: 1611
Code: [Select]
`        if((_currenthp <= 0)){            createRecycledActor(getActorType(0), 320, 400, Script.FRONT);`these are the lines 129,130,131

Seeing this and the error message, maybe your actir type is buggy. Try creating another actor type and see if it works.
The weird thing is that it works perfectly on my computer.  What version of Stencyl do you have ?

#### Exportforce

• Posts: 90
My Build is 8398.

Well, the zero there is "if the hp are zero" but I even already tested to set this to one.
And GetActorType 0 is one of the two possibilities as the list as 2 items. ID 0 and ID 1. So these zeros should be legal too.

#### Exportforce

• Posts: 90
Sorry for the double post, but could it be that the lists are broken ?

I just, for fun, did a test list and wanted to print out the amount of items in it and it clearly is 3 items and yet it kills with a zero error.

Edit: Updated from 3.3.1 to 3.3.2 and now it works... well.. I already did everything right, was truly a bug >.<

Edit 2 (20:27 German time): Okay now I run into another funny bug. I got told  that the content of a value for drawing a rectangle is wrong. The value is a numeric value, always. I manually tried even a 0 and that is fine. So every possible content, which is a number, must be legal, yet sometimes it cries about incorrect value. I am really getting desperate, as I can not find any logical errors, what's 'o ever.

This shows the creation of the enemy. All values verified about 100 times, that they can not be empty or in any range that would be not ok. I even made an extra attribute "createenemy" which is boolean, because "if(current_hp<=0)" and "while(current_hp<=0)" both sometimes created 2 or 3 actors, which is very weird as well, so the loop can never ever create more than one actor.

This shows the creation of my Healthbar-Rectangle and the filler, that displays the health in a %

THIS part gets ignored completely. I can click as I want, neither values change, nor the sound is played.
(I know here it shows "exits" it was just a test of enter and exit if it at least somewhat anyhow reacts)

edit:
Quote
g.fillRect(250, 435, ((_currenthppercent / 100) * 170), 20);
This line sometimes again and again gives me an error, that a parameter would be wrong. But everything that _currenthppercent has in, is numbers and thus can never cause an error.

« Last Edit: July 17, 2015, 02:38:49 pm by Exportforce »

#### yoplalala

• Posts: 1611
Humm, could you post again yout stencyl game ? ( you can do export game, like this there is a stencyl file ). ( or better can you just post the screenshot, with the little camera, it has metadata, and normally I would be able to open it, I have 3.3.1)
It's weird, like this Idon't see anything wrong

#### yoplalala

• Posts: 1611
I neso you wanted to put "when mouse clicks on actor" ?
I never used it wath last created actor so I don't know if it works like this. But for this part, I have a few ideas to make it work ( it just that last time it worked on my computer and not on yours so I'm afraid of saying something now )

#### yoplalala

• Posts: 1611
Maybe put round you (current hp / 100 )*170. As it means pixels, I don't know if you can put 3.5 pixel for example.

(For lists : before you could use he palette to define lists only in behaviors, not direcly in scenes , it  has maybe changed in the new versions.)

« Last Edit: July 18, 2015, 06:18:35 am by yoplalala »