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:

1if xp.Value <= 0 then
2        if xp.Value <=100 then
3            --code
4        else
5            --level 0?
6        end
7    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:

1local rank = 0
2if xp.Value < 100 then
3    rank = 1
4elseif xp.Value < 250 then
5    rank = 2
6elseif xp.Value < 750 then
7    rank = 3
8end
9print(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:

01if xp.Value <= 0 then
02    -- "xp.Value is <= 0"
03 
04    -- The below conditional is useless because the condition
05    --    will always evaluate to true as long as we're in
06    --    this code block: this means line 09 will always run
07    --    and line 11 will never run.
08    if xp.Value <=100 then
09        -- "xp.Value is <= 0 and also <= 100"
10    else
11        -- "xp.Value is <= 0 and is > 100"
12    end
13    -- "xp.Value is <= 0"
14end

Answer this question