# Any ideas on why the leveling system not working?

**URL:** <https://forum.choiceofgames.com/t/any-ideas-on-why-the-leveling-system-not-working/103081>\
**Category:** ChoiceScript Help\
**Created:** [June 26, 2021, 9:09pm UTC](https://forum.choiceofgames.com/t/any-ideas-on-why-the-leveling-system-not-working/103081 "2021-06-26T21:09:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![snail](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/snail/32/153038_2.png) [@snail](https://forum.choiceofgames.com/u/snail)\
**Post date:** [June 26, 2021, 9:09pm UTC](https://forum.choiceofgames.com/t/any-ideas-on-why-the-leveling-system-not-working/103081/1 "2021-06-26T21:09:00Z")

</div>

Hello everyone, this is my third post  
As the title says, I’m currently stuck with the leveling code

I’m creating a level system in excel like this

```
Level Exp Needed Exp Range Total Exp
1 0 0 0
2 1 1 1
3 2 1 3
4 3 1 6
5 4 1 10

```

I’m making 200 level with exp range within each level  
But as I’m writing the code, it just doesn’t connect (I’m still learning here, sorry 😭)

I tried 2 types  
the first is looping with not leveling up and the other does not update the exp needed

My code looks like this:  
1st code:

```
startup.txt

*create level 1
*create exp 0
*create exprange 1
*create expneed
*create totalexp 0
*create ammount 0
*create sp 0

readexp.txt
*comment here is the second choice of leveling code
*set totalexp +exp
*if ((level > 0) and (level < 10))
	*set exprange 1
	*gosub readexp
	*return
*if ((level > 10) and (level < 20))
	*set exprange 2
	*gosub readexp

*label readexp
*set expneed (exp + exprange)
*if (exp >= expneed)
	*set exp -expneed
	*gosub pluslevel
	*return
*else
	*return

*comment here is the +1 level code
*label pluslevel
*set level +1
*set ammount +5
*set sp +5
*return

```

The first code just looping in plus the exp but not leveling up, so if the exp +1 the expneeded becomes 2 and if exp +1 again (makes the exp 2) then the expneeded also +1 which becomes 3 and so the level does not increase

2nd code:

```
startup.txt

*create level 1
*create exp 0
*create exprange 1
*create c_expneed 0
*create n_expneed 0
*create totalexp 0
*create ammount 0
*create sp 0

readexp.txt
*comment here is the second choice of leveling code
*set totalexp +exp
*if ((level > 0) and (level < 10))
	*set exprange 1
	*gosub readexp
	*return
*if ((level > 10) and (level < 20))
	*set exprange 2
	*gosub readexp

*label readexp
*set n_expneed (c_expneed + exprange)
*if (exp >= n_expneed)
	*set exp -n_expneed
	*gosub pluslevel
	*return
*else
	*return

*comment here is the +1 level code
*label pluslevel
*set level +1
*set ammount +5
*set sp +5
*return

```

For the second, the level does increase but the exp needed stays in 1 and not increasing further

Please help me 😭 and THANKS in advance 🙏

---

<div class="post-metadata">

**Author:** ![Nocturnal\_Stillness](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/nocturnal_stillness/32/100414_2.png) [@Nocturnal\_Stillness](https://forum.choiceofgames.com/u/Nocturnal_Stillness)\
**Post date:** [June 26, 2021, 9:15pm UTC](https://forum.choiceofgames.com/t/any-ideas-on-why-the-leveling-system-not-working/103081/2 "2021-06-26T21:15:14Z")

</div>

```
*create exp 0
*create level 1

*label test
You have ${exp} exp and you are currently Level ${level}.
*choice
    #Swing a sword.
        *set exp +25
        *gosub exp_check
        *goto test
    #Fire a bow.
        *set exp +25
        *gosub exp_check
        *goto test

*label exp_check
*if exp >99
    *set level +1
    *set exp 0
    *return
*else
    *return

```

This is just a simple code but should work for a level up system.

---

<div class="post-metadata">

**Author:** ![snail](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/snail/32/153038_2.png) [@snail](https://forum.choiceofgames.com/u/snail)\
**Post date:** [June 26, 2021, 9:20pm UTC](https://forum.choiceofgames.com/t/any-ideas-on-why-the-leveling-system-not-working/103081/3 "2021-06-26T21:20:01Z")

</div>

I did put something like that before

```
*comment here is the second choice of leveling code
*if ((level > 0) and (level <= 5))
	*if exp >= 5
		*set exp -5
		*gosub pluslevel
		*return
	*else
		*return
*if ((level > 5) and (level <= 10))
	*if exp >= 10
		*set exp -10
		*gosub pluslevel
		*return
	*else
		*return
*if ((level > 10) and (level <= 20))
	*if exp >= 20
		*set exp -20
		*gosub pluslevel
		*return
	*else
		*return
*comment here is the +1 level code
*label pluslevel
*set level +1
*set ammount +5
*set sp +5
*return

```

But the thing is, the exp requirement is stuck within the number and can’t increases if you didn’t write the number different on what level.

The thing I want is that when you level up, the exp needed to go to the next level also increases

And thanks for the reply 🙏

---

<div class="post-metadata">

**Author:** ![Nocturnal\_Stillness](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/nocturnal_stillness/32/100414_2.png) [@Nocturnal\_Stillness](https://forum.choiceofgames.com/u/Nocturnal_Stillness)\
**Post date:** [June 26, 2021, 9:51pm UTC](https://forum.choiceofgames.com/t/any-ideas-on-why-the-leveling-system-not-working/103081/4 "2021-06-26T21:51:11Z")

</div>

```
*create exp 0
*create level 1
*create exp_current 50
*create exp_range 50

*label test
You have ${exp} exp and you are currently Level ${level}.
*choice
    #Swing a sword.
        *set exp +25
        *gosub exp_check
        *goto test
    #Fire a bow.
        *set exp +25
        *gosub exp_check
        *goto test

*label exp_check
*if (exp = (exp_current + exp_range))
    *set level +1
    *set exp 0
    *set exp_range +50
    *return
*else
    *return

```

Something like this?

---

<div class="post-metadata">

**Author:** ![snail](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/snail/32/153038_2.png) [@snail](https://forum.choiceofgames.com/u/snail)\
**Post date:** [June 27, 2021, 4:18am UTC](https://forum.choiceofgames.com/t/any-ideas-on-why-the-leveling-system-not-working/103081/5 "2021-06-27T04:18:53Z")

</div>

It’s close and THANKS

By you writing that scripts gives me some insight, and I managed to solved it.

Here is the final code

```
startup.txt

*create level 1
*create exp 0
*create exprange 1
*create expneed 1
*create totalexp 0
*create ammount 0
*create sp 0

*label time_loop
choose
*choice
	#+1
		*set exp +1
		*set totalexp +1
		*gosub_scene readexp
		*goto time_loop
	#+4
		*set exp +4
		*set totalexp +4
		*gosub_scene readexp
		*goto time_loop
	#+9
		*set exp +9
		*set totalexp +9
		*gosub_scene readexp
		*goto time_loop

readexp.txt

*comment here is the second choice of leveling code
*if ((level > 0) and (level < 10))
	*set exprange 1
	*gosub readexp
	*return
*if ((level > 10) and (level < 20))
	*set exprange 2
	*gosub readexp
	*return

*label readexp
*if (exp >= expneed)
	*set exp -expneed
	*gosub pluslevel
	*return
*else
	*return

*comment here is the +1 level code
*label pluslevel
*set expneed +exprange
*set level +1
*set ammount +5
*set sp +5
*return

```

This one increase the range when you level up, and I just realized that you just need to adjust `*set expneed` in the `*label readexp`

Thanks for the insight 🙏

And for anyone who wants exp range increasing on each level with specific ammount you can copy and paste this code 😆

See you guys on my next post 👋

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/choiceofgames/original/3X/e/f/efe1497a762edecdb6d569a1c4abee87508bf002.png) [@system](https://forum.choiceofgames.com/u/system)\
**Post date:** [June 28, 2021, 4:18am UTC](https://forum.choiceofgames.com/t/any-ideas-on-why-the-leveling-system-not-working/103081/6 "2021-06-28T04:18:54Z")

</div>

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.
