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

If Statement, Wrong?


Dastyruck
 Share

Recommended Posts

I am making a crafting system and I ended up with a little bug… I have no idea what is wrong with this statement, however, I know it is the If statement... help?

> If Clicked_Index = 3 Then
>         Call Craft(Index, 3, 1, 8, 2, 45, 1, 44, 3, 46, 1, 0,0,0,0,0,0)
>         Call PlayerMsg(Index, "Got here " , RED)
>     ElseIf Clicked_Index = 5 Then
>         Call Craft(Index, 40, 2, 8, 3, 45, 10, 44, 5, 47, 1, 0,0,0,0,0,0)
>     ElseIf Clicked_Index = 6 Then
>         Call Craft(Index, 42, 2, 8, 3, 45, 15, 44, 2, 46, 1, 0,0,0,0,0,0)
>     ElseIf Clicked_Index = 7 Then
>         Call Craft(Index, 43, 2, 8, 5, 45, 10, 0, 0, 0, 0, 0,0,0,0,0,0)
>     ElseIf Clicked_Index = 9 Then
>         Call Craft(Index, 76, 3, 8, 5, 47, 10, 44, 10, 48, 3, 0,0,0,0,0,0)
>     ElseIf Clicked_Index = 10 Then
>         Call Craft(Index, 77, 3, 8, 3, 47, 15, 44, 5, 48, 2, 0,0,0,0,0,0)
>     ElseIf Clicked_Index = 11 Then
>         Call Craft(Index, 78, 3, 8, 10, 47, 15, 48, 3, 0, 0, 0,0,0,0,0,0)
>     End If
Link to comment
Share on other sites

The If statement looks syntaxally correct; but why not use the Select Case system instead of all those ElseIfs?
e.g.
```
Select Case Clicked_Index
      Case 3
          Call Craft(Index, 3, 1, 8, 2, 45, 1, 44, 3, 46, 1, 0,0,0,0,0,0)
          Call PlayerMsg(Index, "Got here " , RED)
      Case 5
          Call Craft(Index, 40, 2, 8, 3, 45, 10, 44, 5, 47, 1, 0,0,0,0,0,0)
      Case 6
          Call Craft(Index, 42, 2, 8, 3, 45, 15, 44, 2, 46, 1, 0,0,0,0,0,0)
      Case 7
          Call Craft(Index, 43, 2, 8, 5, 45, 10, 0, 0, 0, 0, 0,0,0,0,0,0)
      Case 9
          Call Craft(Index, 76, 3, 8, 5, 47, 10, 44, 10, 48, 3, 0,0,0,0,0,0)
      Case 10
          Call Craft(Index, 77, 3, 8, 3, 47, 15, 44, 5, 48, 2, 0,0,0,0,0,0)
      Case 11
          Call Craft(Index, 78, 3, 8, 10, 47, 15, 48, 3, 0, 0, 0,0,0,0,0,0)
End Select
```
Link to comment
Share on other sites

Well, I looked into it and I cant seem to find a problem… could you try and find something?

> '********************************
> Sub Craft(index, Skill, Item, Tier, Matone, Valone, Mattwo, Valtwo, Matthree, Valthree, Matfour, Valfour, Matfive, Valfive, Matsix, Valsix, Matseven, Valseven)
> '********************************
> Dim matnum
> Dim slot
> Dim has
> Dim need
> Dim mathas
> Dim success
> Dim level
> Dim times
> Dim tier
>
> Call PlayerMsg(Index, "Here we go!", Black)
> If skill = 1 Then
> level = GetVar("scripts\charextras\" & GetPlayerName(index) & ".ini","weaponsmith","level")
> times = GetVar("scripts\charextras\" & GetPlayerName(index) & ".ini","weaponsmith","times")
> ElseIf skill = 2 Then
> level = GetVar("scripts\charextras\" & GetPlayerName(index) & ".ini","armorsmith","level")
> times = GetVar("scripts\charextras\" & GetPlayerName(index) & ".ini","armorsmith","times")
> ElseIf skill = 3 Then
> level = GetVar("scripts\charextras\" & GetPlayerName(index) & ".ini","cooking","level")
> times = GetVar("scripts\charextras\" & GetPlayerName(index) & ".ini","cooking","times")
> ElseIf skill = 4 Then
> level = GetVar("scripts\charextras\" & GetPlayerName(index) & ".ini","alchemy","level")
> times = GetVar("scripts\charextras\" & GetPlayerName(index) & ".ini","alchemy","times")
> ElseIf skill = 5 Then
> level = GetVar("scripts\charextras\" & GetPlayerName(index) & ".ini","bowery","level")
> times = GetVar("scripts\charextras\" & GetPlayerName(index) & ".ini","bowery","times")
> End If
> success = Rand(100,1)
>
> matnum = 0
> mathas = 0
>
> If Matone = 0 Then
> Else
>     matnum = matnum + 1
> End If
> If Mattwo = 0 Then
> Else
>     matnum = matnum + 1
> End If
> If Matthree = 0 Then
> Else
>     matnum = matnum + 1
> End If
> If Matfour = 0 Then
> Else
>     matnum = matnum + 1
> End If
> If Matfive = 0 Then
> Else
>     matnum = matnum + 1
> End If
> If Matsix = 0 Then
> Else
>     matnum = matnum + 1
> End If
> If Matseven = 0 Then
> Else
>     matnum = matnum + 1
> End If
> If matnum >= 1 Then
> slot=1
> has = 0
> need = 1           
> Do While slot < 25 
> If Int(getplayerinvitemnum(index,slot))=Int(Matone) Then
>     If Int(getplayerinvitemvalue(index,slot))>=Int(Valone) Then
>     slot=25
>     has = 1
>     End If                             
> End If 
> slot=slot+1
> Loop
> If Int(has) <> Int(need) Then
>     Call PlayerMsg(Index, "You do not have the proper items or proper amount of items.", RED)
>     Exit Sub
> Else
>     mathas = mathas + 1
>    
> End If
> End If
>
> If matnum >= 2 Then
> slot=1
> has = 0
> need = 1           
>
> Do While slot < 25 
> If Int(getplayerinvitemnum(index,slot))=Int(Mattwo) Then
>     If Int(getplayerinvitemvalue(index,slot))>=Int(Valtwo) Then
>     slot=25
>     has = 1
>     End If                             
> End If 
> slot=slot+1
> Loop
> If Int(has) <> Int(need) Then
>     Call PlayerMsg(Index, "You do not have the proper items or proper amount of items.", RED)
>     Exit Sub
> Else
>     mathas = mathas + 1
>    
> End If
> End If
>
> If matnum >= 3 Then
> slot=1
> has = 0
> need = 1           
>
> Do While slot < 25 
> If Int(getplayerinvitemnum(index,slot))=Int(Matthree) Then
>     If Int(getplayerinvitemvalue(index,slot))>=Int(Valthree) Then
>     slot=25
>     has = 1
>     End If                             
> End If 
> slot=slot+1
> Loop
> If Int(has) <> Int(need) Then
>     Call PlayerMsg(Index, "You do not have the proper items or proper amount of items.", RED)
>     Exit Sub
> Else
>     mathas = mathas + 1
>    
> End If
> End If
>
> If matnum >= 4 Then
> slot=1
> has = 0
> need = 1           
>
> Do While slot < 25 
> If Int(getplayerinvitemnum(index,slot))=Int(Matfour) Then
>     If Int(getplayerinvitemvalue(index,slot))>=Int(Valfour) Then
>     slot=25
>     has = 1
>     End If                             
> End If 
> slot=slot+1
> Loop
> If Int(has) <> Int(need) Then
>     Call PlayerMsg(Index, "You do not have the proper items or proper amount of items.", RED)
>     Exit Sub
> Else
>     mathas = mathas + 1
>
>    
> End If
> End If
>
> If matnum >= 5 Then
> slot=1
> has = 0
> need = 1           
>
> Do While slot < 25 
> If Int(getplayerinvitemnum(index,slot))=Int(Matfive) Then
>     If Int(getplayerinvitemvalue(index,slot))>=Int(Valfive) Then
>     slot=25
>     has = 1
>     End If                             
> End If 
> slot=slot+1
> Loop
> If Int(has) <> Int(need) Then
>     Call PlayerMsg(Index, "You do not have the proper items or proper amount of items.", RED)
>     Exit Sub
> Else
>     mathas = mathas + 1
>    
> End If
> End If
>
> If matnum >= 6 Then
> slot=1
> has = 0
> need = 1           
>
> Do While slot < 25 
> If Int(getplayerinvitemnum(index,slot))=Int(Matsix) Then
>     If Int(getplayerinvitemvalue(index,slot))>=Int(Valsix) Then
>     slot=25
>     has = 1
>     End If                             
> End If 
> slot=slot+1
> Loop
> If Int(has) <> Int(need) Then
>     Call PlayerMsg(Index, "You do not have the proper items or proper amount of items.", RED)
>     Exit Sub
> Else
>     mathas = mathas + 1
>    
> End If
> End If
>
> If matnum >= 7 Then
> slot=1
> has = 0
> need = 1           
>
> Do While slot < 25 
> If Int(getplayerinvitemnum(index,slot))=Int(Matseven) Then
>     If Int(getplayerinvitemvalue(index,slot))>=Int(Valseven) Then
>     slot=25
>     has = 1
>     End If                             
> End If 
> slot=slot+1
> Loop
> If Int(has) <> Int(need) Then
>     Call PlayerMsg(Index, "You do not have the proper items or proper amount of items.", RED)
>     Exit Sub
> Else
>     mathas = mathas + 1
> End If
> End If
>
> If mathas >= matneed Then
>     If mathas >= 1 Then
>         Call quest_Take_Item(index, Matone, Valone)
>     End If
>     If mathas >= 2 Then
>         Call quest_Take_Item(index, Mattwo, Valtwo)
>     End If
>     If mathas >= 3 Then
>         Call quest_Take_Item(index, Matthree, Valthree)
>     End If
>     If mathas >= 4 Then
>         Call quest_Take_Item(index, Matfour, Valfour)
>     End If
>     If mathas >= 5 Then
>         Call quest_Take_Item(index, Matfive, Valfive)
>     End If
>     If mathas >= 6 Then
>         Call quest_Take_Item(index, Matsix, Valsix)
>     End If
>     If mathas >= 7 Then
>         Call quest_Take_Item(index, Matseven, Valseven)
>     End If
>    
> If success <= Int(level)+79 Then
>
> slot=1           
>
> Do While slot < 25 
> If Int(getplayerinvitemnum(index,slot))=0 Then
>     Call SetPlayerInvItemNum(Index, slot, Item)
>     Call SetPlayerInvItemValue(Index, slot, 1)
>     Call SendInventoryUpdate( Index, slot)
>     slot=25                           
> End If 
> slot=slot+1
> Loop
> Call PlayerMsg(Index, "You successfully created 1 " & GetItemName(Item) & "", GREEN)
>
> If skill = 1 Then
> Call Putvar("scripts\charextras\" & GetPlayerName(index) & ".ini","weaponsmith","times",Int(times) + 1)
>
> times = Getvar("scripts\charextras\" & GetPlayerName(index) & ".ini","weaponsmith","times")
>
> If Tier >= level Then
> If level < 20 Then
>     If Int(times) >= Int(level) * 50 Then
>       Call Putvar("scripts\charextras\" & GetPlayerName(index) & ".ini","weaponsmith","level",Int( level) + 1)
>       Call Putvar("scripts\charextras\" & GetPlayerName(index) & ".ini","weaponsmith","times",0)
>       Call PlayerMsg(index, "You gained a level in Weapon Smithing and are now level, " & Int(level) + 1 & "", GREEN)
>     End If
> End If
> End If
> ElseIf skill = 2 Then
> Call Putvar("scripts\charextras\" & GetPlayerName(index) & ".ini","armorsmith","times",Int(times) + 1)
>
> times = Getvar("scripts\charextras\" & GetPlayerName(index) & ".ini","armorsmith","times")
>
> If Tier >= level Then
> If level < 20 Then
>     If Int(times) >= Int(level) * 50 Then
>       Call Putvar("scripts\charextras\" & GetPlayerName(index) & ".ini","armorsmith","level",Int( level) + 1)
>       Call Putvar("scripts\charextras\" & GetPlayerName(index) & ".ini","armorsmith","times",0)
>       Call PlayerMsg(index, "You gained a level in Armor Smithing and are now level, " & Int(level) + 1 & "", GREEN)
>     End If
> End If
> End If
> ElseIf skill = 3 Then
> Call Putvar("scripts\charextras\" & GetPlayerName(index) & ".ini","cooking","times",Int(times) + 1)
>
> times = Getvar("scripts\charextras\" & GetPlayerName(index) & ".ini","cooking","times")
>
> If Tier >= level Then
> If level < 20 Then
>     If Int(times) >= Int(level) * 50 Then
>       Call Putvar("scripts\charextras\" & GetPlayerName(index) & ".ini","cooking","level",Int( level) + 1)
>       Call Putvar("scripts\charextras\" & GetPlayerName(index) & ".ini","cooking","times",0)
>       Call PlayerMsg(index, "You gained a level in Cooking and are now level, " & Int(level) + 1 & "", GREEN)
>     End If
> End If
> End If
> ElseIf skill = 4 Then
> Call Putvar("scripts\charextras\" & GetPlayerName(index) & ".ini","alchemy","times",Int(times) + 1)
>
> times = Getvar("scripts\charextras\" & GetPlayerName(index) & ".ini","alchemy","times")
>
> If Tier >= level Then
> If level < 20 Then
>     If Int(times) >= Int(level) * 50 Then
>       Call Putvar("scripts\charextras\" & GetPlayerName(index) & ".ini","alchemy","level",Int( level) + 1)
>       Call Putvar("scripts\charextras\" & GetPlayerName(index) & ".ini","alchemy","times",0)
>       Call PlayerMsg(index, "You gained a level in Alchemy and are now level, " & Int(level) + 1 & "", GREEN)
>     End If
> End If
> End If
> ElseIf skill = 5 Then
> Call Putvar("scripts\charextras\" & GetPlayerName(index) & ".ini","bowery","times",Int(times) + 1)
>
> times = Getvar("scripts\charextras\" & GetPlayerName(index) & ".ini","bowery","times")
>
> If Tier >= level Then
> If level < 20 Then
>     If Int(times) >= Int(level) * 50 Then
>       Call Putvar("scripts\charextras\" & GetPlayerName(index) & ".ini","bowery","level",Int( level) + 1)
>       Call Putvar("scripts\charextras\" & GetPlayerName(index) & ".ini","bowery","times",0)
>       Call PlayerMsg(index, "You gained a level in Bowery and are now level, " & Int(level) + 1 & "", GREEN)
>     End If
> End If
> End If
> End If
>
> Else
> Call PlayerMsg(Index, "You failed to craft 1 " & GetItemName(Item) & "", RED)
>  
> End If
>
> End If
> End Sub
Link to comment
Share on other sites

@Dastyruck:

> Well, I looked into it and I cant seem to find a problem… could you try and find something?

But have you tested it, as I asked?
If you tested it, and it works, then there's an alternate error that doesn't concern that sub,
As I said, just throw this command under Case 1 in the Hotscripts sub:
Call Craft(Index, 40, 2, 8, 3, 45, 10, 44, 5, 47, 1, 0,0,0,0,0,0)
Then press "Page Up" in-game, and see if the sub executes.
Link to comment
Share on other sites

here: [http://winkey.org/~cody/VbScript_Editor.Exe](http://winkey.org/~cody/VbScript_Editor.Exe)
quite simple, and it doesn't bug out on getvars like the one in the announcments section.

Just put the script you're wanting to debug in there(sub name to end sub) and press f5
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...