generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Game Design
Home Search
 

Re: My brain! I need math help pl0x D:

Previous Thread :: Next Thread 
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
09 Apr 2015 03:29 PM
So I wanted to use some guis to display health, ammo, etc...
The idea was that there were 9 bars, each representing 1/9th of maximum hp, ammo, etc etc

For example, if there was 90 max value, each bar would represent a total of 10, since 90 divided by 9 is 10. Same with 180, each bar would be 20. Or at 500, each bar is 55.56.

It's not a set value. The bars are what divides the max value into 9ths, each bar getting more and more transparent as the local value falls until it's completely invisible in which case it goes to the next bar.

For example, if the max value was 90, each bar is 10 value. if the value fell from 90 to 80, 8 bars would still be visible while the 9th bar would be completely transparent. If the value had only fallen to 85, 8 bars would be perfectly visible while the 9th would be only half transparent.

Does this make sense? Was I clear enough for this? To be honest I had no idea how to explain what I was attempting to do.
Report Abuse
gamehero is not online. gamehero
Joined: 12 Jun 2007
Total Posts: 1455
09 Apr 2015 04:07 PM
I probably misunderstood the instruction, but it this was fun to make nevertheless.
It's just a prototype of course... You can edit "MyValue" in Workspace in real time to see if it changes the way it should in test mode.


parts = {}
val = workspace:FindFirstChild("MyValue")
MAX = 90

if not val then
val = Instance.new("IntValue",workspace)
val.Value = MAX
val.Name = "MyValue"
end

model = workspace:FindFirstChild("Prototype")
if model then
model:Destroy()
end

model = Instance.new("Model",workspace)
model.Name = "Prototype"

for i=1,MAX/10 do
local part = Instance.new("Part",model)
part.CFrame = CFrame.new(0,22,i*2)
part.Anchored = true
table.insert(parts,part)
end


val.Changed:connect(function()
local START = math.floor((MAX-val.Value)/10)+1
--if START == 0 then START = 1 print("SET") end
print("START",START)
if parts[START] then
for i=1,START do
parts[i].Transparency = 1
end
for i=START,#parts do
print(i,val.Value/10)
parts[i].Transparency = 0
end
print((-val.Value%10)/10,(-val.Value%10)/10)
parts[START].Transparency = (-val.Value%10)/10
end
end)

Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
09 Apr 2015 04:45 PM
@OP

I will see if I can accomplish that, although this is more math than I usually use.


I script -~ chimmihc
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
09 Apr 2015 04:53 PM
Definitely misunderstood lol... Well, kind of. You got part of it right.

Guis, not parts. Exactly 9 guis not 10. The idea is that the MaxValue is divided by 9.

If 90 was the max value, then each bar would represent a value of 10, 1/9th of maxvalue.
If the local value is 90, all 9 bars are visible.
At 85, 8 bars are visible while the 9th bar is half transparent.
at 50, 5 bars would be visible while the last 4 are fully transparent.
At 5, all the bars are fully transparent except the first bar, which would be half transparent.
At 1, all bars are transparent except the first bar which is 0.9 transparency.

See what I'm doing? Nothing is generated. It's all already there. I'm simply adjusting the transparency of these 9 guis to represent the current Value out of MaxValue.

Adjusting the parts transparency you got sort of right, but I can't reference the math because you generated 10 parts, which wasn't supposed to happen at all. There are guis, not parts, and only 9. The 9 guis are the only set number that should be appearing.


The concept is basically a health bar, except that instead of resizing a health bar, we're changing the animation to adjust each section's transparency to account for that fraction of health.

Since there are 9 bars, the MaxValue is divided into 9 chunks. Each gui bar is responsible for representing its 1/9th fraction of the MaxValue. As each bar's chunk decreases or increases in value, the transparency is adjusted.



I don't know how to explain that any clearer. If people still don't understand then I guess I have to abandon my project. This is important.
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
09 Apr 2015 05:08 PM
I can always rely on chimmi :o
Report Abuse
gamehero is not online. gamehero
Joined: 12 Jun 2007
Total Posts: 1455
09 Apr 2015 05:37 PM
I prototype with parts because I'm more familiar with them and it's easier to demonstrate. Anyway, I made the adjustments you asked me to make.
The demonstration script goes in the StarterGui.

Now if I still got something wrong, I'll adjust some more. It sounds like I'm on the right track so far.

pgui = script.Parent
bars = {}
val = workspace:FindFirstChild("MyValue")
MAX = 90
NumBars = 9

if not val then
val = Instance.new("IntConstrainedValue",workspace)
val.MaxValue = MAX
val.Value = MAX
val.Name = "MyValue"
end

sc = pgui:FindFirstChild("Prototype")
if sc then
sc:Destroy()
end

sc = Instance.new("ScreenGui",pgui)
sc.Name = "Prototype"

for i=1,NumBars do
local f = Instance.new("Frame",sc)
f.Size = UDim2.new(0,100,0,10)
f.Position = UDim2.new(0,10,0,i*15)
table.insert(bars,f)
end


val.Changed:connect(function()
local Div = val.MaxValue/NumBars
print("MATH",(val.MaxValue-val.Value)/Div)
local START = math.floor((val.MaxValue-val.Value)/Div)+1
if START == 0 then START = 1 print("SET") end
print("START",START,bars[START],val.MaxValue/Div)

for i=1,#bars do
bars[i].Transparency = 1
end
for i=START,#bars do
if bars[i] ~= nil then
bars[i].Transparency = 0
end
end
if bars[START] then
bars[START].Transparency = (-val.Value%Div)/Div
end
--end
end)

Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
09 Apr 2015 05:51 PM
Nailed it perfectly. I can use that as a reference to set up everything I need. I really appreciate it and I'm sorry I was so difficult to help.
Report Abuse
championbuilder is not online. championbuilder
Joined: 20 Jan 2009
Total Posts: 13544
09 Apr 2015 05:57 PM
Where do you get these insane ideas omg.
Report Abuse
gamehero is not online. gamehero
Joined: 12 Jun 2007
Total Posts: 1455
09 Apr 2015 06:02 PM
Nah, you weren't difficult to help. It's just that the script is so hard to describe even to me. I'm bad at following instructions anyway. This is good practice.
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
09 Apr 2015 06:39 PM
Well I was wrong. It's almost perfect.
This is what I used to test after modifying it. I removed the generation, and pathed to my hud to see how it would affect it, and apparently with a MaxValue of 500, something goes wrong and the gui doesn't use decimals in the transparency. At 500 MaxValue, changing the value resulted in either a 0 or 1 transparency. Wouldn't change to anything in between. I'm still trying to wrap my head around how this actually works.


Hud = script.Parent.HUD
Tray = Hud.Tray
Shield = Tray.S3Shield
SV = script.Parent.ShieldValue

local NumBars = nil

local Bins = Shield:GetChildren()
NumBars = #Bins

SV.Changed:connect(function()
local Div = SV.MaxValue/NumBars

local START = math.floor((SV.MaxValue-SV.Value)/Div)+1

if START == 0 then START = 1 end

for i = 1, #Bins do
Bins[i].Bar.Transparency = 1
end

for i = START, #Bins do
if Bins[i] ~= nil then
Bins[i].Bar.Transparency = 0
end
end
if Bins[START] then
Bins[START].Transparency = (-SV.Value%Div)/Div
end
end)
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
09 Apr 2015 06:47 PM
Found another issue too. I ran a for loop in the command bar to countdown the value from Max to zero, and towards the end, it made the bars disappear in this order:
1, 2, 3, 4, 5, 6, 8, 9, 7.

I may have messed something up. I honestly don't know.
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
09 Apr 2015 07:05 PM
i threw a print((-SV.Value%Div)/Div) in there and it's printing decimal values like it should, but for some reason the guis aren't changing that way.
Report Abuse
gamehero is not online. gamehero
Joined: 12 Jun 2007
Total Posts: 1455
09 Apr 2015 07:06 PM
Maybe the bars were created in the wrong order. Each bar has to be ordered from top to bottom. Chances are you created the bars in that order from 6, but then did something on the 7th bar. Does the prototype function with the same problem? I don't see any transparency going from 1 to 0.
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
09 Apr 2015 07:10 PM
Transparency issue fixed. It was bad pathing, but the order in which the gui bars are disappearing is still wrong. Some reason that must have been my fault caused 8 and 9 to disappear before 7.
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
09 Apr 2015 07:12 PM
I checked, double checked, and then triple checked. Then I checked again. Physically, the gui bars are fine. They're all in the right order and they're all positioned the way I want them. I must have messed something up in the script when I changed it that caused it to go wacky on me.
Report Abuse
gamehero is not online. gamehero
Joined: 12 Jun 2007
Total Posts: 1455
09 Apr 2015 07:17 PM
Did you test it like this?

for i = 1, #Bins do
print(Bins[i],"==",i,"?")
end

If the numbers don't align by the 7th bar, then you know something is wrong.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
09 Apr 2015 07:21 PM
@OP

Right now I'm making a health bar with the method you want, it's done except for the bar representing what ninth of the amount it is on's transparency changing depending on tenths of the ninth.


I script -~ chimmihc
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
09 Apr 2015 07:25 PM
Bin1 == 1 ?
Bin2 == 2 ?
Bin3 == 3 ?
Bin4 == 4 ?
Bin5 == 5 ?
Bin6 == 6 ?
Bin8 == 7 ?
Bin9 == 8 ?
Bin7 == 9 ?


I said the exact same thing in my previous reply. Doesn't mean I know how to fix it. Everything looks fine to me.
Report Abuse
gamehero is not online. gamehero
Joined: 12 Jun 2007
Total Posts: 1455
09 Apr 2015 07:26 PM
It's how you built it. Rename Bin8 to Bin7, and Bin9 to Bin8, and Bin7 to Bin9 and reposition them.
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
09 Apr 2015 07:31 PM
I have no words...
Report Abuse
gamehero is not online. gamehero
Joined: 12 Jun 2007
Total Posts: 1455
09 Apr 2015 07:34 PM
Uh, I hope that's a good thing. Or else the alternative is this:

Bins = {Shield.Bar1,Shield.Bar2, ...}
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
09 Apr 2015 07:39 PM
Shield["Bin"..START].Bar.Transparency = (-SV.Value%Div)/Div
--Bins[START].Bar.Transparency = (-SV.Value%Div)/Div


Went with a more direct approach and... Well, it kinda worked but then again it didn't really.
7 disappeared before 8 like it should have, but after it disappeared it reappeared before 8 and 9 did their thing.


Either the GetChildren() method is glitching, or there's something wrong with the START math.




Chimmi I would love to see what you got lol...
Report Abuse
gamehero is not online. gamehero
Joined: 12 Jun 2007
Total Posts: 1455
09 Apr 2015 07:46 PM
The START variable is very weird... I don't trust it for reading arrays. You can say GetChildren() is glitching. I can't seem to glitch my prototype.
You can either rename the objects, or manually create a table as I suggested above and see what happens.
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
09 Apr 2015 07:56 PM
lol darn it. I hate doing things manually. Makes it a pain when I have to change something xD
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
09 Apr 2015 08:01 PM
My brain has died trying to get the formula for the bar fading in tenths of the ninth it is on.


I script -~ chimmihc
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Game Design
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image