Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Why does my script keep breaking?


Squiddle
 Share

Recommended Posts

Hi everyone! Well, I'm working on the Skills for Kitten Online, and I'm getting an error. Well, actually, it isn't an RTE. It's just a script breaking after use :S.

Now, this is in my Sub MenuScripts:

```
Sub MenuScripts(Index, Clicked_Index, Menu_Type)
Dim MenuTitle
Dim FieldMessage
Dim AlchemyLevel
Dim NewAlchemyLevel
Dim EXPReward

MenuTitle = getplayermenuclicktitle(Index)
FieldMessage = getplayermenuclickmsg(Index)
AlchemyLevel = GetVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyLevel")
NewAlchemyLevel = GetVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyLevel") + 1

Select Case Menu_Type
Case 1
    If Clicked_Index = 0 Then
    EXPReward = GetVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyEXP") + 10
        If CanTake(Index, 16, 1) Then
                    If CanTake(Index, 15, 1) Then
                        If GetFreeSlots(Index) > 0 Then
                            Call TakeItem(Index, 15, 1)
                            Call TakeItem(Index, 16, 1)
                            Call GiveCurrency(Index, 17, 1)
                            Call PlayerMsg(index, "You made 1 Energy Potion!", YELLOW)
                            Call BattleMsg(index, "You gained 10 Alchemy Experience Points!", WHITE, 0)
                            Call PutVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyEXP", (EXPReward))
                            If GetVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyEXP") >= GetVar("Scripts\AlchemyEXP.ini", "EXP", "Level" & AlchemyLevel) Then
                                Call PutVar("Scripts\Charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyLevel", (NewAlchemyLevel))
                                Call PutVar("Scripts\Charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyEXP", 0)
                                Call BattleMsg(index, "You have gained a level in Alchemy!", YELLOW, 0)
                                Call PlayerMsg(index, "You are now level " & NewAlchemyLevel & " in the Alchemy Skill!", YELLOW)
                                Call SpellAnim(6, GetPlayerMap(Index), GetPlayerX(Index), GetPlayerY(Index))
                            End If
                        Else
                            Call PlayerMsg(index, "You need 1 free inventory slot to preform this action.", YELLOW)
                        End If
                    Else
                        Call PlayerMsg(index, "You need Mew Berries to preform this action!", YELLOW)
                    End If
                Else
                    Call PlayerMsg(index, "You need a Jar of Honey to preform this action!", YELLOW)
                End If
            End If

```And yes, you can use that if abosolutely neccissary

Now, in that script it reads off of an AlchemyEXP.ini, located in the Scripts folder. Here is what's in that Ini:
```
[EXP]
Level1=25
Level2=50
Level3=75
Level4=100
Level5=150
Level6=200
Level7=250
Level8=300
Level9=350
Level10=400

```
Now, at first all of that works all happpy whiskers and smiling puppies, but all of a sudden it breaks :(. At about level 3-4, you start leveling up every time you activate that script, regardless of how much EXP you actually have :(.

Now if anyone can help me with this, please do :).
Link to comment
Share on other sites

just a few random things i like to mention ^^
```
EXPReward = GetVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyEXP") + 10
```should be…
```
EXPReward = Int(GetVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyEXP")) + 10
```
For some odd partially guessable reason, you have parenthesis' around your EXPReward variable here…
```
Call PutVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyEXP", (EXPReward))
```again here…```
If GetVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyEXP") >= GetVar("Scripts\AlchemyEXP.ini", "EXP", "Level" & AlchemyLevel) Then
```you should have int() around getvars when comparing numbers…

again parenthesis'..
```
Call PutVar("Scripts\Charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyLevel", (NewAlchemyLevel))
```
i could say more, but where would the fun be in that? hahaha!
Link to comment
Share on other sites

Int() converts a string, to an integer… so "1" is 1 when it reads it... because when you try to add strings... it just links them togethor... ex: "3" + "2" = "32"
and i say you should wrap it around getvars whenever it involves numbers..
Link to comment
Share on other sites

Okay. But when I remove the Parenthesis', I get RTEs :(. Type Mismatch: "PutVar". Here's my Sub now:
```
Sub MenuScripts(Index, Clicked_Index, Menu_Type)
Dim MenuTitle
Dim FieldMessage

MenuTitle = getplayermenuclicktitle(Index)
FieldMessage = getplayermenuclickmsg(Index)
AlchemyLevel = GetVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyLevel")
NewAlchemyLevel = int(GetVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyLevel")) + 1

Select Case Menu_Type
Case 1
    If Clicked_Index = 0 Then
    EXPReward = int(GetVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyEXP")) + 10
        If CanTake(Index, 16, 1) Then
                    If CanTake(Index, 15, 1) Then
                        If GetFreeSlots(Index) > 0 Then
                            Call TakeItem(Index, 15, 1)
                            Call TakeItem(Index, 16, 1)
                            Call GiveCurrency(Index, 17, 1)
                            Call PlayerMsg(index, "You made 1 Energy Potion!", YELLOW)
                            Call BattleMsg(index, "You gained 10 Alchemy Experience Points!", WHITE, 0)
                            Call PutVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyEXP", EXPReward)
                            If int(GetVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyEXP")) >= GetVar("Scripts\AlchemyEXP.ini", "EXP", "Level" & AlchemyLevel) Then
                                Call PutVar("Scripts\Charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyLevel", NewAlchemyLevel)
                                Call PutVar("Scripts\Charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyEXP", 0)
                                Call BattleMsg(index, "You have gained a level in Alchemy!", YELLOW, 0)
                                Call PlayerMsg(index, "You are now level " & NewAlchemyLevel & " in the Alchemy Skill!", YELLOW)
                                Call SpellAnim(6, GetPlayerMap(Index), GetPlayerX(Index), GetPlayerY(Index))
                            End If
                        Else
                            Call PlayerMsg(index, "You need 1 free inventory slot to preform this action.", YELLOW)
                        End If
                    Else
                        Call PlayerMsg(index, "You need Mew Berries to preform this action!", YELLOW)
                    End If
                Else
                    Call PlayerMsg(index, "You need a Jar of Honey to preform this action!", YELLOW)
                End If
            End If

```
Link to comment
Share on other sites

```
Sub MenuScripts(Index, Clicked_Index, Menu_Type)
  Dim MenuTitle
  Dim FieldMessage

  MenuTitle = getplayermenuclicktitle(Index)
  FieldMessage = getplayermenuclickmsg(Index)
  AlchemyLevel = GetVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyLevel")
  NewAlchemyLevel = int(GetVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyLevel")) + 1

  Select Case Menu_Type
      Case 1     
          If Clicked_Index = 0 Then
            EXPReward = int(GetVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyEXP")) + 10
              If CanTake(Index, 16, 1) Then
                          If CanTake(Index, 15, 1) Then
                              If GetFreeSlots(Index) > 0 Then
                                    Call TakeItem(Index, 15, 1)
                                    Call TakeItem(Index, 16, 1)
                                    Call GiveCurrency(Index, 17, 1)
                                    Call PlayerMsg(index, "You made 1 Energy Potion!", YELLOW)
                                    Call BattleMsg(index, "You gained 10 Alchemy Experience Points!", WHITE, 0)
                                    Call PutVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyEXP", EXPReward & "")
                                    If int(GetVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyEXP")) >= Int(GetVar("Scripts\AlchemyEXP.ini", "EXP", "Level" & AlchemyLevel)) Then
                                        Call PutVar("Scripts\Charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyLevel", NewAlchemyLevel & "")
                                        Call PutVar("Scripts\Charextras\" & GetPlayerName(Index) & ".ini", "SKILLS", "AlchemyEXP", 0)
                                        Call BattleMsg(index, "You have gained a level in Alchemy!", YELLOW, 0)
                                        Call PlayerMsg(index, "You are now level " & NewAlchemyLevel & " in the Alchemy Skill!", YELLOW)
                                        Call SpellAnim(6, GetPlayerMap(Index), GetPlayerX(Index), GetPlayerY(Index))
                                    End If
                              Else
                                    Call PlayerMsg(index, "You need 1 free inventory slot to preform this action.", YELLOW)
                              End If
                          Else
                              Call PlayerMsg(index, "You need Mew Berries to preform this action!", YELLOW)
                          End If
                  Else
                      Call PlayerMsg(index, "You need a Jar of Honey to preform this action!", YELLOW)
                  End If
              End If

```try that..
Link to comment
Share on other sites

@DNA:

> Int stands for integer which is a WHOLE number.
>
> …It can also be for negative whole numbers...
> ...Not sure if you'd call it _whole_ though.

The Int() function returns the integer part of the number; if it's a decimal, it will convert it into a whole number.

If you want a number with a decimal, I suggest CDbl(), which is like Int(), but returns a double (which allows a decimal).
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...