I am thinking of my next tease idea, and would like to include health bar type idea (so bar fills up or empties depending on what happens in the tease) like in computer games (think every fighting game)
I have no idea if this is possible in EOS so any help would be great
EOS Question - Health bar
Moderator: 1885
-
- Explorer At Heart
- Posts: 483
- Joined: Sat Jun 01, 2013 8:01 pm
- Gender: Male
- Sexual Orientation: Straight
- I am a: Switch
EOS Question - Health bar
Try anything once!
-
- Explorer At Heart
- Posts: 265
- Joined: Thu Jan 03, 2013 4:55 pm
- Gender: Male
- Sexual Orientation: Straight
- I am a: Submissive
Re: EOS Question - Health bar
boundupone wrote: ↑Sun Nov 15, 2020 12:09 pm I am thinking of my next tease idea, and would like to include health bar type idea (so bar fills up or empties depending on what happens in the tease) like in computer games (think every fighting game)
I have no idea if this is possible in EOS so any help would be great
This is just a draft idea that came to me; I'm in no way expert of JavaScript nor I have ever created a working tease, but taking some inspiration from viewtopic.php?f=2&t=23415 you can use a notification with only a title set to be a sequence of "█" for part of the bar that is full and "░" for part of the bar that is emptied.
If you create a notification named health and you've got a variable curHealth in your variables you could go something like this in an eval action:
Code: Select all
var healthBar="Health\t";
for (i = 0; i < 10; i++) {
if(i<curHealth){
healthBar += "█";
}else{
healthBar += "░";
}
}
Notification.get("health").setTitle(healthBar);
You can test it here:
https://milovana.com/webteases/showteas ... 666fca9467
-
- Explorer At Heart
- Posts: 483
- Joined: Sat Jun 01, 2013 8:01 pm
- Gender: Male
- Sexual Orientation: Straight
- I am a: Switch
Re: EOS Question - Health bar
That is exactly what I want to do, thank you. But I am having difficulty replicating, can you share the code please for your demo so I can see it all.
Cheers
Cheers
Try anything once!
-
- Explorer At Heart
- Posts: 265
- Joined: Thu Jan 03, 2013 4:55 pm
- Gender: Male
- Sexual Orientation: Straight
- I am a: Submissive
Re: EOS Question - Health bar
boundupone wrote: ↑Sun Nov 15, 2020 2:15 pm That is exactly what I want to do, thank you. But I am having difficulty replicating, can you share the code please for your demo so I can see it all.
Cheers
Code: Select all
"start": [
{
"notification.create": {
"id": "health",
"title": "Health"
}
},
{
"eval": {
"script": "var curHealth=10;\r\n\r\nvar healthBar=\"Health\\t\";\r\nfor (i = 0; i < 10; i++) {\r\n if(i<curHealth){\r\n healthBar += \"█\";\r\n }else{\r\n healthBar += \"░\";\r\n }\r\n}\r\n\r\nNotification.get(\"health\").setTitle(healthBar);"
}
},
{
"say": {
"label": "<p>Start</p>",
"mode": "pause"
}
},
{
"say": {
"label": "<p>You suffered damage </p>",
"mode": "pause"
}
},
{
"eval": {
"script": "var curHealth=8;\r\n\r\nvar healthBar=\"Health\\t\";\r\nfor (i = 0; i < 10; i++) {\r\n if(i<curHealth){\r\n healthBar += \"█\";\r\n }else{\r\n healthBar += \"░\";\r\n }\r\n}\r\n\r\nNotification.get(\"health\").setTitle(healthBar);"
}
}
]
-
- Explorer At Heart
- Posts: 483
- Joined: Sat Jun 01, 2013 8:01 pm
- Gender: Male
- Sexual Orientation: Straight
- I am a: Switch
Re: EOS Question - Health bar
Thanks, I am still missing something, maybe I am not doing the init script for the var right?
var curHealth=0;
var curHealth=0;
Try anything once!
-
- Explorer At Heart
- Posts: 483
- Joined: Sat Jun 01, 2013 8:01 pm
- Gender: Male
- Sexual Orientation: Straight
- I am a: Switch
-
- Explorer At Heart
- Posts: 265
- Joined: Thu Jan 03, 2013 4:55 pm
- Gender: Male
- Sexual Orientation: Straight
- I am a: Submissive
Re: EOS Question - Health bar
I've got a more "Advanced" version of the solution I posted before.boundupone wrote: ↑Sun Nov 15, 2020 2:41 pm Thanks, I am still missing something, maybe I am not doing the init script for the var right?
var curHealth=0;
In your intiScript define:
Code: Select all
var maxHealth=10; //defines max characeter health
var curHealth=maxHealth; //defines starting health
var healthBarLength=10; //defines how many "█" are used to represent health
function updateHeathBar() {
var healthBar="Health\t";
var threshold=healthBarLength*curHealth/maxHealth;
for (i = 0; i < healthBarLength; i++) {
if(i<threshold){
healthBar += "█";
}else{
healthBar += "░";
}
}
Notification.get("health").setTitle(healthBar);
}
Code: Select all
updateHeathBar();
Code: Select all
curHealth-=2; //for 2 damage; use += for healing
updateHeathBar();
-
- Explorer At Heart
- Posts: 483
- Joined: Sat Jun 01, 2013 8:01 pm
- Gender: Male
- Sexual Orientation: Straight
- I am a: Switch
Re: EOS Question - Health bar
awesome, that works perfectly, thanks for your help
Try anything once!
Who is online
Users browsing this forum: Astralis125 and 13 guests