Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Variables Help

Yo! Yeah, I'm trying mmy hand at eventing by creating a new minning and smithing system. Although before I can I need help with variables (random ones for the most part). My two questions are:

1. How do you set a variable so you have a 10-30% chance of finding mythril?

2. How do you set up a variable that will generate a number depending on the number of the item in stock? Ex. Say you had 20 pieces of copper and wanted to refine all of them. The selection only goes up to 10 so you would hit the "All" button, but how would I make it so it gives you 20 copper bars?
 

Zeriab

Sponsor

Question 1
When you say 10-30% chance does it mean that the percentage changes during the game?
Assuming static percentage the standard way is to set a variable to a value between 0 and 99 and then creating a conditional branch structure. For an example look here:
chance.png


If you want to have many branches then the inwards grow can be confusing and a structure like the one below can be preferable:
chance2.png


The first is simpler to understand, but becomes more complex when having many possible branches. The second is short and sweet, but the flow is harder to see especially when it is placed into a context. Labels can be used instead, but are more error prone and increase complexity.
Use which way you prefer for your case.

Question 2
If I am understanding this correctly then you have an input variable with only one digit.
You need to have a Control Variables... event command where you set the amount of Pieces of Copper to a variable.
You can use a conditional branch on this variable to check whether it's less than 10 (1 digit) or not (2 digits).
Use the Input Number... event command with the digits depending on the branch.
You can then remove the amount of pieces of copper and add the same amount of bars to the inventory.
pieces_to_bars.png


You should deal with exceptional cases, e.g:
pieces_to_bars_eh.png

I check for the case where more pieces are selected than are present in the inventory. I also check if there is enough room for the extra bars.
You can see them as the conditional branches which only have a comment in them.
How you deal with these exceptional cases is up to you. It's possible that you would want a different structure. I am just showing one way of dealing with the problem.

The ALL button you are talking about is simple Amount = Pieces.

*hugs*
- Zeriab
 

Zeriab

Sponsor

You have to do more than simply copying what I got.
The conditional branch with the comment Not enough pieces and the conditional branch with Not enough room. You have to fill them out.
You could for example put Exit Event Processing commands in them. (Page 1 of the event commands, left column, 5th from the bottom.)

*hugs*
- Zeriab
 
I didn't just copy it, since the comment butoon seams to do nothing in game. Thanks for the help though. Udidn't think about that button since I have never used it.

EDIT: Gah! I hate variables! It doesn't seem to recognize the variable "Pieces" (to tell how many are in stock). As soon as I can figure out that problem then I can finnally finish this.
 

Zeriab

Sponsor

I used the comments only to explain what the different parts of the events do.
The comments have no effect in game.

About your problem, can you post a picture of your event?
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top