Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My brain can't seem to handle what I'm trying to do?

Asked by 7 years ago

So, I'm trying to make it so you have an overall experience, and you level up whenever that hits a certain point(that I set for each)

For example:

Rank 1 - hit 0 XP(obviously) Rank 2 -100 XP Rank 3 -250 XP rank 4 - 750 XP

I tried something like this:

if xp.Value <= 0 then
        if xp.Value <=100 then
            --code
        else
            --level 0?
        end
    end
0
If you mean what the script is doing is that for LINE 1: Checking if the XP is greater than or equal to 0 so no negative numbers come in-tact, LINE 2: Checking if the XP is greater than 100 which would mean you pass LEVEL 1 i'm guessing, LINE 5: I don't see a point towards the else, unless you want it to do something if it's NOT that amount of XP. xEiffel 280 — 7y

2 answers

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
7 years ago

I think elseif may be what you’re looking for with something like this:

local rank = 0
if xp.Value < 100 then
    rank = 1
elseif xp.Value < 250 then
    rank = 2
elseif xp.Value < 750 then
    rank = 3
end
print(rank)
0
Thanks, I feel like a legitimate idiot, but I appreciate it haha getzedotus 0 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

To make reading conditionals (if statements) and their blocks easier, make sure to properly indent your code. It seems like you might need a bit more practice with conditionals, so if you haven't already, read through this wiki page about conditional statements. In any case, I've indented and commented your code to help understand what you've got. I hope it helps, and doesn't make things more confusing for you:

if xp.Value <= 0 then
    -- "xp.Value is <= 0"

    -- The below conditional is useless because the condition
    --    will always evaluate to true as long as we're in
    --    this code block: this means line 09 will always run
    --    and line 11 will never run.
    if xp.Value <=100 then
        -- "xp.Value is <= 0 and also <= 100"
    else
        -- "xp.Value is <= 0 and is > 100"
    end
    -- "xp.Value is <= 0"
end

Answer this question