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
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Is there a way I can simplify this?

Previous Thread :: Next Thread 
i_Movie is not online. i_Movie
Joined: 06 Apr 2014
Total Posts: 11725
26 Mar 2016 07:59 PM
pcall(function()
while wait(1) do
if Level.Text == "Current Level: 1" then
BrickCount.Value = BrickCount.Value+(AddBricks+1)
elseif Level.Text == "Current Level: 2" then
BrickCount.Value = BrickCount.Value+(AddBricks+3)
elseif Level.Text == "Current Level: 3" then
BrickCount.Value = BrickCount.Value+(AddBricks+6)
elseif Level.Text == "Current Level: 4" then
BrickCount.Value = BrickCount.Value+(AddBricks+12)
elseif Level.Text == "Current Level: 5" then
BrickCount.Value = BrickCount.Value+(AddBricks+18)
end
end
end)

I used pcall so it doesn't crash the script if it errors.


Report Abuse
i_Movie is not online. i_Movie
Joined: 06 Apr 2014
Total Posts: 11725
26 Mar 2016 08:01 PM
1


Report Abuse
i_Movie is not online. i_Movie
Joined: 06 Apr 2014
Total Posts: 11725
26 Mar 2016 08:03 PM
2


Report Abuse
me2kool2talk2u is not online. me2kool2talk2u
Joined: 19 Feb 2007
Total Posts: 2914
26 Mar 2016 08:03 PM
pcall(function()
while wait(1) do
local lvl = tonumber(string.sub(Level.Text, 16))
if lvl == 1 then
BrickCount.Value = BrickCount.Value+(AddBricks+1)
elseif lvl == 2 then
BrickCount.Value = BrickCount.Value+(AddBricks+3)
elseif lvl == 3 then
BrickCount.Value = BrickCount.Value+(AddBricks+6)
elseif lvl == 4 then
BrickCount.Value = BrickCount.Value+(AddBricks+12)
elseif lvl == 5 then
BrickCount.Value = BrickCount.Value+(AddBricks+18)
end
end
end)

Cleans things up a bit, should work. May have to screw around with the string.sub
Report Abuse
i_Movie is not online. i_Movie
Joined: 06 Apr 2014
Total Posts: 11725
26 Mar 2016 08:05 PM
I assume string.sub substitutes for the max level I can go up


Report Abuse
me2kool2talk2u is not online. me2kool2talk2u
Joined: 19 Feb 2007
Total Posts: 2914
26 Mar 2016 08:06 PM
http://wiki.roblox.com/index.php?title=Function_dump/String_manipulation#string.sub
Report Abuse
i_Movie is not online. i_Movie
Joined: 06 Apr 2014
Total Posts: 11725
26 Mar 2016 08:06 PM
I'm going all the way up to level 50, and I think it's just a lot of code, I want to simplify it down to like 5 lines if possible.


Report Abuse
me2kool2talk2u is not online. me2kool2talk2u
Joined: 19 Feb 2007
Total Posts: 2914
26 Mar 2016 08:07 PM
You would need to come up with a mathematical equation/algorithm to calculate the amount of max parts based on level.
Report Abuse
i_Movie is not online. i_Movie
Joined: 06 Apr 2014
Total Posts: 11725
26 Mar 2016 08:08 PM
Well, I know that, but I'm not sure how to do it. (No, I'm not asking for you to script it for me, I'm just asking what I need to do it)


Report Abuse
me2kool2talk2u is not online. me2kool2talk2u
Joined: 19 Feb 2007
Total Posts: 2914
26 Mar 2016 08:10 PM
"Creating formulas like this requires knowledge of elementary mathematical functions - the things you learned about in Algebra and Pre-calculus class.

Once you have those mastered, just ask yourself (replace "value" with "damage," or "health," or "speed" or whatever):

Do you want the value to grow at a constant rate? Use a linear function.
Do you want the value to grow slow at first, but fast later? Use a polynomial or exponential function.
Do you want the value to grow fast at first, and slow down later? Use an nth-root or logarithmic function.
Do you want the value to grow slowly at the start/end but fast in the middle? Or do you want it to grow quickly but still have an upper-bound? Use a sigmoid curve, such as atan or the logistic function.
Do you want the value to oscillate? Use a sin or some other wave.
Then just tweak it (add/multiply stuff, change the base-value, etc) until it feels right. A graphing calculator will help you visualize how changes to the parameters will affect the function."

source: http://gamedev.stackexchange.com/questions/14309/how-to-develop-rpg-damage-formulas
Report Abuse
i_Movie is not online. i_Movie
Joined: 06 Apr 2014
Total Posts: 11725
26 Mar 2016 08:14 PM
e.e

Yeah, I don't understand that kind of stuff. gg

I'm not even in calculus, in geometry right now... rip


Report Abuse
me2kool2talk2u is not online. me2kool2talk2u
Joined: 19 Feb 2007
Total Posts: 2914
26 Mar 2016 08:16 PM
If you're in geometry you should understand that. You learn mathematical functions in basic algebra.
Report Abuse
rockslide103 is not online. rockslide103
Joined: 24 Mar 2012
Total Posts: 1161
26 Mar 2016 08:18 PM
@i_movie your in middle school still?


Report Abuse
i_Movie is not online. i_Movie
Joined: 06 Apr 2014
Total Posts: 11725
26 Mar 2016 08:18 PM
Well no, the thing I'm tripping over is the fact that I don't even know the right equation for this.

It has a specific level.

If the level is a specific number then it adds 6 to the added value.


Report Abuse
me2kool2talk2u is not online. me2kool2talk2u
Joined: 19 Feb 2007
Total Posts: 2914
26 Mar 2016 08:19 PM
So there's your equation:

bricks = (level*6) + 1
Report Abuse
i_Movie is not online. i_Movie
Joined: 06 Apr 2014
Total Posts: 11725
26 Mar 2016 08:20 PM
@rock

lol, I'm a sophomore in highschool, and I never work with mathematical equations in LUA, it's a first time type of thing, so I literally don't know how to start or what to start with.


Report Abuse
i_Movie is not online. i_Movie
Joined: 06 Apr 2014
Total Posts: 11725
26 Mar 2016 08:27 PM
"bricks = (level*6) + 1"

That is terribly wrong. lol......


Ur multiplying the current level * 6 then adding 1? e.e

Everytime the level goes up 1, it adds on 6 to the adder.


Report Abuse
me2kool2talk2u is not online. me2kool2talk2u
Joined: 19 Feb 2007
Total Posts: 2914
26 Mar 2016 08:30 PM
Welp I thought that's what you said. Sorry mate. No better time to learn incorporating math into your code :)
Report Abuse
i_Movie is not online. i_Movie
Joined: 06 Apr 2014
Total Posts: 11725
26 Mar 2016 08:33 PM
Lmao, I am so lost.



Report Abuse
i_Movie is not online. i_Movie
Joined: 06 Apr 2014
Total Posts: 11725
26 Mar 2016 08:45 PM
If someone could save me a headache and simplify this for me, that'd be great. Because I'm not wasting all night trying to fix this.


Report Abuse
i_Movie is not online. i_Movie
Joined: 06 Apr 2014
Total Posts: 11725
26 Mar 2016 08:51 PM
1


Report Abuse
i_Movie is not online. i_Movie
Joined: 06 Apr 2014
Total Posts: 11725
26 Mar 2016 08:57 PM
2


Report Abuse
Cuyler is not online. Cuyler
Joined: 27 Feb 2006
Total Posts: 3784
26 Mar 2016 09:01 PM
ypcall(function() --//Needs to be ypcall() since a yield is called. (wait(1))
while wait(1) do
local lvl = tonumber(Level.Text:match("%d+")) or 1 --//Get Level
local LevelBrickCount = function(x)
return math.floor( 0.5 + (0.7857 * x^2 - (0.4143) * x + 0.6) ) --//Calculate Additional Bricks
end
BrickCount.Value = BrickCount.Value + (AddBricks + LevelBrickCount(lvl)) --//Add Additional Bricks
end
end)


Report Abuse
Lamar is not online. Lamar
Joined: 18 Nov 2006
Total Posts: 523
26 Mar 2016 09:03 PM
You should make the level a variable, then update the Level Text using that variable with concatenation. For example:

local lvl = 1
Level.Text = "Current Level: "..lvl

Then, you can simplify it like this.

pcall(function()
while wait(1) do
BrickCount.Value = BrickCount.Value + (AddBricks*lvl, or whatever equation you end up using to calculate the amount of bricks to add)
end
end)

Let variables and functions do all the work for you.
Report Abuse
Tynezz is not online. Tynezz
Joined: 28 Apr 2014
Total Posts: 4945
26 Mar 2016 09:07 PM
pcall(function()
while wait(1) do
local LevelValue=tonumber(Level.Text:sub((Level.Text:find('Current Level: ')+1)))
BrickCount.Value=LevelValue==1 and (AddBricks+1) or LevelValue==2 and (AddBricks+3) or (AddBricks+(LevelValue*2))
end
end)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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