Battle type data help

Hello,

I’m a relative noob at Bubble but I feel like I may have just hit a bit of a wall in what I’m trying to do, and wanted to know if I’m just missing something.

I’d like to set up my database as a player character, and allow the character to attack monsters (and vice versa). Right now, I’m trying to have the monster have a set amount of HP that, at the click of a button, is whittled away by the users attack stat. I’ve set up the monsters as a data type, which has it’s own HP percentage. No matter what I try though, I can’t seem to get everything I need to work. It seems so easy in my head but bubble doesn’t seem to want to allow me to do this… Any help would be amazing.

I can expound if it doesn’t make sense. I realize this is probably extremely niche, but if I can get it to work I should be successful getting the rest of my app set up the way I need it.

Thanks!

I’m sure that’s not the case… you just don’t yet know how to do what you’re trying to do (whatever that is)…

I can expound if it doesn’t make sense.

You’re going to have to if you want any real help here… but from what you’ve described already, it doesn’t sound too complicated…

So, go ahead and share some more specific details about what you’re trying to do (and what you’re already doing), and I’m sure someone can point you in the right direction…

Thanks for the reassurance.

Alright, I’ll try to explain this as well as I can… I am trying create a user “player character” and a monster “character” that will be battled. My player character is connected to the current user, and has different stats in different fields of my database. I want a user to be able to click a button to start a “battle” where they will be fighting a monster. When the user goes into the battle they load the monster and the monster’s HP will display.

The player then clicks the attack button, and using their stats (plus a random number generator) will either be successful or they will “miss”. On a hit, the monster will subtract from their total HP amount the amount of the players stat field “attack damage”. The monster would do all the above as well to the player. Once the monster’s HP hits 0, it triggers the victory screen etc. If a player’s HP hits 0 a different event is triggered.

I can’t for the life of me figure out how to set up a monster “database” set that allows me to subtract an HP value from a User stat value.

I’m also having difficulty using my random number generator plugin PLUS my players stats. Essentially, it seems like my roadblock at the moment is using number values and being able to successfully add or subtract them in a way the allows me to utilize the sum of those values in a workflow.

My opinion would be to use the database as a starting health point. Create a health state on the Page element or something relevant equal to the starting health and subtract from it.

I’m guessing you’re using random numbers to simulate collisions?

Right, I’m trying to have a random number generated from 1-100, then take that value and add the user’s “melee attack” field’s value, and if the sum is above a threshold (let’s say 50) the attack would hit. Then the user’s “attack damage” value would be subtracted from the monster’s current health.

You say random number gen plugin, have you tried Bubble’s Generate Formula operator?

2 Likes

… didn’t realize that was a thing.

It’s at the forefront of selections when you’re wanting to give it dynamic data.

Do you mean this?

Yer! we out here. Calculate random string. I think it’s zero based, so the max should be 99?

But don’t use this for remaining HP… For your attack. Right?

Right, The random value is something I use in the workflow.

Set those values as states as well. Should make for better performance than updating a database every instance.

When you say set those as states, are you talking about this?


If so, how should I go about creating the health starting point state and having it actually display that on the page? I’ll admit I’ve never used states before…If this is noob 101 stuff I’ll just go watch some tutorials if it will cover my needs haha. Bubble in the last few days has made me feel like an absolute genius and a moron in a very short timespan lol.

1 Like

You can access the states like any other data. And you can set the state to a Player’s health, and a monster with monsters health. Then just subtract from either when you need to

1 Like

Hi there, @snarec… you were obviously in good hands with Doug, but it seemed like it would be fun to create an example for this one, so I did exactly that, and it was, indeed, fun.

The example I made only handles the attack from the player perspective, and here are the data types and fields I used.

Also, the User data type has a player field that links to the Player data type.

I added two custom states at the page level, and those states are monster hit points and melee plus random.

Next, I added a group to the page, and the group and the two text elements in the group look like this.

Above the group, I have a Battle button, and the workflow actions for that button look like this.

Finally, after the Battle button is clicked, there is an Attack button that can be clicked again and again, and the workflow actions for that button look like this.

Anyway, that might be a lot more than you wanted here, but again, it was fun to build it out, and I hope it helps you get down a good path.

Best…
Mike

P.S. To test my example, I called the monster a Snarec, which is a damn good monster name, if you ask me. :slight_smile:

4 Likes

:bowing_man: we out here :bowing_man:

1 Like

Wow, this is fantastic! I can’t quite seem to get it to work, but I’ll definitely need to spend more time parsing through your example so I can actually understand exactly what’s happening and what I might be messing up.

Thanks so much for the help, either way you’ve gotten me a lot closer to getting what I need to make this thing work!

Also, love that you made me the monster name haha! Seems apt.

1 Like

My pleasure, friend. If you need more help as you go, feel free to hit me up. Hell, I’d build this one out for free because it seems pretty cool.

1 Like

Haha, I’ll see what I can do and will likely hit you up with more questions. Super tempting to just have you build it, but I’m planning on it being a game I can continually build out over time, so I’ll need to figure it out eventually. I’d like to see if I can actually wrap my head around this stuff and I figure there’s no better way than struggling for days on end until I get it :sweat_smile:

1 Like