[Tutorial] Variables and Overlays - How to draw variables on an overlay :)

Started by mega1134227 on Thu, 05/16/2019 - 22:50

Topic category: User side tutorials

Last seen on 02:45, 16. Aug 2019
Joined Feb 2016
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
[Tutorial] Variables and Overlays - How to draw variables on an overlay :)
Fri, 05/17/2019 - 13:35 (edited)

Okay so, in this tutorial I'll teach some of you how to draw variables on your screen (or just numbers to those whom are simply oblivious to the term "variable" such as my good friend Mark right here on my right...)

First thing you should know is that in java there are 3 main types of variables : "strings", which are just a line of characters to which you can "add" more characters, integers which are the same as doubles with the slight exception that Ints (integers) don't count decimal numbers and doubles do (there are many other types...) and finally, logic variables which are just a failproof way of making true or flase statement...

To "draw" a variable on your overlay you'll need to use a String. Notice how I say "draw." In Minecrafts code, it says it "draws" its variables when it uses an overlay and Minecraft can only draw strings as far as I know... But, there is a problem... When you add something to a String, it doesn't do it like you do in Math class or like Ints do, it just stacks it on top of the previous line...

 

Ex: 1 + 1 gives 11 or a + 1 gives a1

Minecraft.getMinecraft().fontRenderer.drawString("1" + "1",posX + 183, posY + 73, -16711732);

This would draw 11...

 

So, the question is, how do you draw a number that can change? It's actually pretty simple. We'll just have to use alongside the String an Int since you can add Ints or doubles to a String. The way to do this is to add an Int without putting it under String form (or you'll get an error) to an empty string (ex: "") using a "+" and puting the whole addition thingy between parentheses because it won't work otherwise... (It didn't for me)

 

Like this:

Minecraft.getMinecraft().fontRenderer.drawString(("" + mcreator_VarListminecraft_worlds.WorldVariables.get(entity.world).soul),
                            posX + 183, posY + 73, -16711732);

 

Using these you can add in many quirky systems such as an energy system or a money system and many other things! :)

Just don't forget to use your mods name instead of my Minecraft Worlds Mod name [mcreator_VarListminecraft_worlds], your type of variable save (World, Map or Session) [WorldVariables.get(entity.world)] and your own variables name [soul]... :^l

Also, if you want to have your procedures to actively update your variable on your overlay... I recommend to use the "On player tick update" thingy in your procedures. I am saying this because this is a problem that I managed to fix alone, but that, in all honesty, took me way to long to fix...

Hope this helped you!

Edited by mega1134227 on Fri, 05/17/2019 - 13:35
Last seen on 16:42, 18. Aug 2019
Joined Apr 2010
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
  • developer
Nice tutorial, we will fix…
Fri, 05/17/2019 - 16:24

Nice tutorial, we will fix this in next update too :)

Last seen on 02:45, 16. Aug 2019
Joined Feb 2016
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Thx ^^
Sat, 05/18/2019 - 13:56

Thx ^^