Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / [SOLVED] simple health bar not working correctly

Author
Message
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 20th Nov 2021 04:17
This post has been marked by the post author as the answer.
i have a simple health bar code that seems to only work for full health and no health, meaning the size only changes when its dead

The author of this post has marked a post as an answer.

Go to answer

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 20th Nov 2021 04:36
I made this a while ago if its any help

I actually have an updated version of that include here somewhere on a HDD with text overlays and stuff, I'll see if I can find it.
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 20th Nov 2021 04:41 Edited at: 20th Nov 2021 04:46
I had renamed it to "ProgressBar", but the same thing

ProgressBar.agc






Edit: [c]/[m] are placeholder to automatically insert "Current, Maximum" values

How that helps
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee

Attachments

Login to view attachments
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 20th Nov 2021 04:47
thats great! thank you ill be looking at that for sure. my original code is still bugging me though lol
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 20th Nov 2021 04:52
lol, as I remember the math was a little tricky to get right, a static bar is easy enough but making it dynamic was a bit of a challenge.
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 20th Nov 2021 04:59
i need to work on making functional code like that instead of hundreds of lines setting positions and so on
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 20th Nov 2021 05:09 Edited at: 20th Nov 2021 05:10
Yeah I like to write modular code, if you think of everything in your game as an independent system and code it as such you then build a library of "drop in" solutions for the next projects.

Actually, looking over that code it could use some refactoring, and the text is not getting deleted, the functional part is good though I just have not used it in a project so there are edge cases you might need to catch.
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 20th Nov 2021 16:34
omg i had an extra "p" in progress somewhere..............
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 20th Nov 2021 16:57
HaHa, it happens ...

You can use #Option_Explicit to avoid stuff like that, it makes AppGameKit act more like C (for example) so you have to declare variables first and anything not declared (like progress with 2 p's lol) will get pinged by the compiler
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 20th Nov 2021 22:36
so when i use optionexplict my for i loops come up as i isnt defined like this one
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 20th Nov 2021 23:01 Edited at: 20th Nov 2021 23:03
#option_explicit is very strict.

ie, your variable i isn't explicitly declared.

so, something like:

is required before you use it.
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 20th Nov 2021 23:21
I see thank you. Is it better to locally declare i for every loop or to use global once?
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 21st Nov 2021 02:48
Noooooooo!

Generally speaking you want to avoid globals *where you can*, I would declare locally every time.
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Nov 2021 08:18
Quote: "pprogress_step = Aliennumber*100.0/totalaliens/100
setspritesize(wave.hpbarfront, pprogress_step*300,20)"


This confuses me. Should be as simple as:
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 21st Nov 2021 08:37
Its only easy, when you know how
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 21st Nov 2021 16:36 Edited at: 21st Nov 2021 17:14
si i tried something..... now im just unclear how to add "name" and ".hpbarfront"

im thinking i need to convert the "name" into a string then add the ".hpbarfront" inside the function but im not sure how
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 21st Nov 2021 22:11
Change
createhealthbar(name as string

to

createhealthbar(name as alienspawnType
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 21st Nov 2021 22:58 Edited at: 21st Nov 2021 23:34
ok i see but i have 4 different alien types each have up to 9 of them aliena, alienb, alienc and aliend each have hp bars im trying to create. so basically i want to be able to use "name", (aliena,alienb,alienc,aliend) then the alien number (0- alien.length)
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 22nd Nov 2021 16:49
Hmm, ok

problem is you are referencing type fields and AppGameKit needs to know what type the fields belong to, so you need to either

1. use a single generic type all aliens use
2. use a select inside the function to set the right type fields
3. have the function return a healthbar type which you then apply to the alien type outside the function
4. have a createhealthbar function for each alien type.

either way you are going to have to rethink and restructure your code
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 23rd Nov 2021 04:17
Quote: "2. use a select inside the function to set the right type fields"

Could you explain this to me better or show me where to research it?
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 23rd Nov 2021 19:31
so im going to put the aliens under a s ingle type like in the code below then try to construct it inside the function i just need to figure out how to reconstruct it inside im guessing turning the val into a string maybe

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 23rd Nov 2021 19:37
Quote: "function createhealthbar(name as allaliens_type ,posx,posy,visible,sizex,sizey,rired,igreen,iblue,ialpha)"
mind your typos, unless you really want no red in your aliens
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 23rd Nov 2021 20:03
name.aliena[i].hpbarfront >> but you are still going to have the same problem, no matter how many ways you try to work around it you can not have 1 function apply type fields for different types, I get what you are trying to do but AppGameKit just will not allow it like this.

dummyaliena and alienaspawntype both contain the same fields (id, img, x, y) so just use this type for ALL aliens and just omit the fields you do not need in alien b,c,d etc, consolidate into a single type and reuse, then you can have your createhealthbar function work on all aliens

Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 25th Nov 2021 14:31
Quote: " I get what you are trying to do but AppGameKit just will not allow it like this."
guess i just have trouble accepting no for an answer lol but thanks for the help. im just mainly trying simplify my code and functions now that i know a little bit of what im doing

Login to post a reply

Server time is: 2024-04-19 02:32:30
Your offset time is: 2024-04-19 02:32:30