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

Run-Time error 340, Can't get around it


Zamin
 Share

Recommended Posts

Hello,

I am having this silly error which I can not seem to get around. I am using EE 2.7.0 and I did read the [Bugs & Errors Guide](http://www.touchofdeathforums.com/smf/index.php/topic,12254.0.html) Post.

This error occurs in a custom, but simple quest script I am trying to make. I spent over a day trying to find what I am doing wrong but can't find any errors in my code. I will paste the code below.

In Sub JoinGame(index)
```
If GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1") = "" Then
Call PutVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "QuestDesc1", "Example Quest")
Call PutVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1", 0)
Call PutVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "QuestDesc2", "Example Quest2")
Call PutVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest2", 0)
End If

```
Very top of Sub MenuScripts(index)
```
Dim Quest1
Dim Quest2
Quest1 = GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1")
Quest2 = GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest2")

```
Again in Sub MenuScripts(index), after Case Menu_Type (after this entire select case)
```
If Clicked_Index = 12 And Quest1 = 0 Then
    Call PutVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1", 1)
    Call CustomMenuClose(Index)
    Call CustomMenuShow(Index, "QuestExtra", "\GUI\CUSTOM\QuestExtra\Menu.gif", 1)
    Call CustomMenuLabel(Index, 70, "Thank you for accepting this quest. Try to get my stick as soon as possible.", 3, 3, 8, 0, 0, 190, 200)
ElseIf Clicked_Index = 13 And Quest1 = 0 Then
    Call CustomMenuClose(Index)
    Call CustomMenuShow(Index, "QuestExtra", "\GUI\CUSTOM\QuestExtra\Menu.gif", 1)
    Call CustomMenuLabel(Index, 70, "Come back when you have changed your mind!", 3, 3, 8, 0, 0, 190, 200)
ElseIf Clicked_Index = 16 And Quest1 = 1 Then
    Call CustomMenuClose(Index)
    Call CustomMenuShow(Index, "QuestExtra", "\GUI\CUSTOM\QuestExtra\menu.gif", 1)
    Call CustomMenuLabel(Index, 72, "Then why are you still here?", 3, 3, 8, 0, 0, 190, 200)
ElseIf Clicked_Index = 15 And Quest1 = 1 Then
    Call CustomMenuClose(Index)
    Call QuestExtra(Index)
End If

If Clicked_Index = 22 And Quest2 = 0 And Quest1 = 2 Then
    Call PutVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest2", 1)
    Call CustomMenuClose(Index)
    Call CustomMenuShow(Index, "QuestExtra2", "\GUI\CUSTOM\QuestExtra\Menu.gif", 1)
    Call CustomMenuLabel(Index, 70, "Thank you for accepting this quest. Try to get my lever as soon as possible.", 3, 3, 8, 0, 0, 190, 200)
ElseIf Clicked_Index = 23 And Quest2 = 0 And Quest1 = 2 Then
    Call CustomMenuClose(Index)
    Call CustomMenuShow(Index, "QuestExtra2", "\GUI\CUSTOM\QuestExtra\Menu.gif", 1)
    Call CustomMenuLabel(Index, 70, "Come back when you have changed your mind!", 3, 3, 8, 0, 0, 190, 200)
ElseIf Clicked_Index = 26 And Quest2 = 1 And Quest1 = 2 Then
    Call CustomMenuClose(Index)
    Call CustomMenuShow(Index, "QuestExtra2", "\GUI\CUSTOM\QuestExtra\Menu.gif", 1)
    Call CustomMenuLabel(Index, 72, "Then why are you still here?", 3, 3, 8, 0, 0, 190, 200)
ElseIf Clicked_Index = 25 And Quest2 = 1 And Quest1 = 2 Then
    Call CustomMenuClose(Index)
    Call QuestExtra2(Index)
End If

```
In Sub ScriptedNPC(index), Case 2 in my case
```
Case 2
    Call CustomMenuClose(Index)
    Call CustomMenuShow(Index, "QuestExtra", "\GUI\CUSTOM\QuestExtra\Menu.gif", 1)
    If GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1") = 2 And GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest2") = 2 Then
          Call CustomMenuLabel(Index, 7, "You have completed all the quests!", 3, 3, 8, 0, 0, 190, 200)
          Exit Sub
    End If
    If GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1") = 0 Then
          Call CustomMenuLabel(Index, 11, "I need you to get me a stick!", 3, 3, 8, 0, 0, 190, 200)
          Call CustomMenuLabel(Index, 12, "Accept Quest!", 3, 260, 8, 5, 0, 200, 15)
          Call CustomMenuLabel(Index, 13, "Deny Quest!", 3, 280, 8, 5, 0, 200, 15)
    ElseIf GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1") = 1 Then
          Call CustomMenuLabel(Index, 14, "Do you have the stick?", 3, 3, 8, 0, 0, 190, 200)
          Call CustomMenuLabel(Index, 15, "Have Quest Item!", 3, 260, 8, 5, 0, 200, 15)
          Call CustomMenuLabel(Index, 16, "Do Not Have Quest Item!", 3, 280, 8, 5, 0, 200, 15)
    End If
    If GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1") = 2 Then
          Call PlayerMsg(Index, "Test2", WHITE) 'Test 2 - worked
          'Call CustomMenuClose(Index)    Do I need this line here? I mean, theoretically.
          Call CustomMenuShow(Index, "QuestExtra2", "\GUI\CUSTOM\QuestExtra\Menu.gif", 1)
          If GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest2") = 0 Then
              Call CustomMenuLabel(Index, 21, "I need you to get me a lever!", 3, 3, 8, 0, 0, 190, 200)
              Call CustomMenuLabel(Index, 22, "Accept Quest!", 3, 260, 8, 5, 0, 200, 15)
              Call CustomMenuLabel(Index, 23, "Deny Quest!", 3, 280, 8, 5, 0, 200, 15)
          ElseIf GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest2") = 1 Then
              Call CustomMenuLabel(Index, 24, "Do you have my lever?", 3, 3, 8, 0, 0, 190, 200)
              Call CustomMenuLabel(Index, 25, "Have Quest Item!", 3, 260, 8, 5, 0, 200, 15)
              Call CustomMenuLabel(Index, 26, "Do Not Have Quest Item!", 3, 280, 8, 5, 0, 200, 15)
          End If
    End If
    Exit Sub

```
Then finally at the end of Main.txt
```
'-=-=-=-=-=-=-=-=-=-
Sub QuestExtra(Index)
'-=-=-=-=-=-=-=-=-=-
    Call CustomMenuClose(Index)
    Call CustomMenuShow(Index, "QuestExtra", "\GUI\CUSTOM\QuestExtra\Menu.gif", 1)
    If CanTake(Index, 3, 1) = false Then
          Call CustomMenuLabel(Index, 90, "You didn't get the item! Go buy it from the merchant!", 3, 3, 8, 0, 0, 190, 200)
    Else
          Call TakeItem(index, 3, 1)
          Call GiveCurrency(index, 1, 99)
          Call CustomMenuLabel(Index, 91, "Thanks, here's your reward!", 3, 3, 8, 0, 0, 190, 200)
          Call PutVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1", 2)
    End If
End Sub

'-=-=-=-=-=-=-=-=-=-
Sub QuestExtra2(Index)
'-=-=-=-=-=-=-=-=-=-
    Call CustomMenuClose(Index)
    Call CustomMenuShow(Index, "QuestExtra2", "\GUI\CUSTOM\QuestExtra\Menu.gif", 1)
    If CanTake(Index, 3, 1) = false Then
          Call CustomMenuLabel(Index, 92, "You didn't get the item! Go buy it from the merchant!", 3, 3, 8, 0, 0, 190, 200)
    Else
          Call TakeItem(index, 3, 1)
          Call GiveCurrency(index, 1, 99)
          Call CustomMenuLabel(Index, 93, "Thanks, here's your reward!", 3, 3, 8, 0, 0, 190, 200)
          Call PutVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest2", 2)
    End If
End Sub

```
Menu Bg Image: http://i6.photobucket.com/albums/y220/Zamin/Menu.gif
Name It: Menu.gif
Place it in client folder in \GUI\CUSTOM\QuestExtra

Ok, I hope I didn't miss anything. Lol. Ok, what happens is that you click scripted npc, prompt opens and everything happens. I made a different custom menu per quest. QuestExtra for quest1 and QuestExtra for Quest2\. I don't think I need to explain the entire code.

So the custom menu's open, I click on the given options (accept or deny quest). I used Clicked_index to determine where user clicked. Ok. What happens is that the script is very glitchy. Sometimes when I hit 'ctrl' in front of NPC, the menu opens and closes instantly. I looked through my code very carefully and I didn't see any extra 'CustomMenuClose(Index)' Calls.

Another problem is that sometimes I get an error '340' It says something like this:
```
'Run-time error '340':
'Control array element '11' doesn't exist

```I think this is the array element being used in the Sub ScriptedNPC(index). For some reason the server thinks the given info does not exist? The element doesn't have to be '11' all the time. It changes everytime from 11-16 and 21-26\. This error terminates the cleint completely. When I try a few times, without any change, the problem dissapears. I am having trouble pin-pointing my error. I think the first problem I listed above is a elading problem to this one.

This is pretty much all I can say to describe this problem, sorry. I know its very confusing. It would be awesome if someone can actually try this script a few times and encounter the problem. Hopefully you do encounter the problem.

Please try to help me on this. This is my first script btw. I still think c++ is much easier than this frown-script :(

-Thanks in advance to all
Link to comment
Share on other sites

MY OPINION:
```
If GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1") = "" Then
Call PutVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "QuestDesc1", "Example Quest")
Call PutVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1", 0)
Call PutVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "QuestDesc2", "Example Quest2")
Call PutVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest2", 0)
End If
```
Although getting the null CAN and SHOULD work.. i dont recommend it…

Isnt there a sub for when you make the character.. through just the putvars in there.
---------------------------------------------------------------------------------------------------------

MY SUGGESTON:
try commenting out everything not absolutely required... like all the commands run inside the ifs, then try it.
Slowly add steps in and retry... sooner or later you will see some silly obvious mistake. I do it all the time.
Link to comment
Share on other sites

Hello,

@SW: There is no problem in making the .ini file, so I guess the null works and isn't the problem in my case. Thanks though.

OK, i did many tests and modifications; and I think I know where my problem is, but I can't pin point it.

In Sub ScriptedNPC
```
Case 2
    Call CustomMenuShow(Index, "QuestExtra", "\GUI\CUSTOM\QuestExtra\Menu.gif", 1)
    If Int(GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1")) = 2 And Int(GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest2")) = 2 Then
          Call CustomMenuLabel(Index, 7, "You have completed all the quests!", 3, 3, 8, 0, 0, 190, 200)
          Exit Sub
    ElseIf Int(GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1")) = 0 Then
          Call CustomMenuLabel(Index, 11, "I need you to get me a stick!", 3, 3, 8, 0, 0, 190, 200)
          Call CustomMenuLabel(Index, 12, "Accept Quest!", 3, 260, 8, 5, 0, 200, 15)
          Call CustomMenuLabel(Index, 13, "Deny Quest!", 3, 280, 8, 5, 0, 200, 15)
    ElseIf Int(GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1")) = 1 Then
          Call CustomMenuLabel(Index, 14, "Do you have the stick?", 3, 3, 8, 0, 0, 190, 200)
          Call CustomMenuLabel(Index, 15, "Have Quest Item!", 3, 260, 8, 5, 0, 200, 15)
          Call CustomMenuLabel(Index, 16, "Do Not Have Quest Item!", 3, 280, 8, 5, 0, 200, 15)

    ElseIf Int(GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1")) = 2 Then            'Quest 2 begins
          If Int(GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest2")) = 0 Then
              Call CustomMenuLabel(Index, 21, "I need you to get me a lever!", 3, 3, 8, 0, 0, 190, 200)
              Call CustomMenuLabel(Index, 22, "Accept Quest!", 3, 260, 8, 5, 0, 200, 15)
              Call CustomMenuLabel(Index, 23, "Deny Quest!", 3, 280, 8, 5, 0, 200, 15)
          ElseIf Int(GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest2")) = 1 Then
              Call CustomMenuLabel(Index, 24, "Do you have my lever?", 3, 3, 8, 0, 0, 190, 200)
              Call CustomMenuLabel(Index, 25, "Have Quest Item!", 3, 260, 8, 5, 0, 200, 15)
              Call CustomMenuLabel(Index, 26, "Do Not Have Quest Item!", 3, 280, 8, 5, 0, 200, 15)
          End If
    End If
    Exit Sub

```
I think this is where the problem lies because what happens is when I hit 'ctrl' in front of the NPC, sometimes the prompt opens and closes instantly. And I guess it recieves a null value which leads to the run-time error '340' of element array missing.

Please help me on this.

-Thanks in advance
Link to comment
Share on other sites

That code skips indexes all over the place, you can't have a 15 without a 1-14 and you can't have a 25 without a 1-25, so, when using If's in custommenu's you have to remember which label is where, which you want replaced and so on, and so forth.. really it's no different from a player's index *nod nod* silly goodie
Link to comment
Share on other sites

@Bobosk:

> That code skips indexes all over the place, you can't have a 15 without a 1-14 and you can't have a 25 without a 1-25, so, when using If's in custommenu's you have to remember which label is where, which you want replaced and so on, and so forth.. really it's no different from a player's index *nod nod* silly goodie

Player Index doesn't really work like that. It simply means the source code doesn't keep track of the indices which is obviously a mistake by the developers not by the scripters. Scripters already have to take too much into concern.

Regards,
  Godlord.
Link to comment
Share on other sites

@Bobosk:

> Well, either way, that's the way it works, so if you can't get used to it, i suggest you hire out from now on for custommenu's

I never had problems with it. It's just illogical that you're forced to use ascending numbers everywhere.

Regards,
  Godlord.
Link to comment
Share on other sites

@Bobosk:

> yesh, you're right, now then… Let's make us a building, except, we'll skip floors 3-5 and just leave those empty!

Possible, you'd only need walls and stability, you don't need any furniture, wallpapers, paint, decoration, etc. to be there and the decoration and furniture is exactly what custom menu's are.

Regards,
  Godlord.
Link to comment
Share on other sites

Thank you both for good responces.

@Bobosk:

> That code skips indexes all over the place, you can't have a 15 without a 1-14 and you can't have a 25 without a 1-25, so, when using If's in custommenu's you have to remember which label is where, which you want replaced and so on, and so forth.. really it's no different from a player's index *nod nod* silly goodie

Just wondering, do I have to 'call' the labels according to the index numbers? Like, call 1, then 2 then 3, etc… Or can I name all of them and the manu's can be called in any order.

I have another problem. I posted this code above:
```
Case 2
    Call CustomMenuShow(Index, "QuestExtra", "\GUI\CUSTOM\QuestExtra\Menu.gif", 1)
    If Int(GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1")) = 2 And Int(GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest2")) = 2 Then
          Call CustomMenuLabel(Index, 7, "You have completed all the quests!", 3, 3, 8, 0, 0, 190, 200)
          Exit Sub
    ElseIf Int(GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1")) = 0 Then
          Call CustomMenuLabel(Index, 11, "I need you to get me a stick!", 3, 3, 8, 0, 0, 190, 200)
          Call CustomMenuLabel(Index, 12, "Accept Quest!", 3, 260, 8, 5, 0, 200, 15)
          Call CustomMenuLabel(Index, 13, "Deny Quest!", 3, 280, 8, 5, 0, 200, 15)
    ElseIf Int(GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1")) = 1 Then
          Call CustomMenuLabel(Index, 14, "Do you have the stick?", 3, 3, 8, 0, 0, 190, 200)
          Call CustomMenuLabel(Index, 15, "Have Quest Item!", 3, 260, 8, 5, 0, 200, 15)
          Call CustomMenuLabel(Index, 16, "Do Not Have Quest Item!", 3, 280, 8, 5, 0, 200, 15)

    ElseIf Int(GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest1")) = 2 Then            'Quest 2 begins
          If Int(GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest2")) = 0 Then
              Call CustomMenuLabel(Index, 21, "I need you to get me a lever!", 3, 3, 8, 0, 0, 190, 200)
              Call CustomMenuLabel(Index, 22, "Accept Quest!", 3, 260, 8, 5, 0, 200, 15)
              Call CustomMenuLabel(Index, 23, "Deny Quest!", 3, 280, 8, 5, 0, 200, 15)
          ElseIf Int(GetVar("Scripts\Quest\" & GetPlayerName(Index) & ".ini", "QUESTS", "Quest2")) = 1 Then
              Call CustomMenuLabel(Index, 24, "Do you have my lever?", 3, 3, 8, 0, 0, 190, 200)
              Call CustomMenuLabel(Index, 25, "Have Quest Item!", 3, 260, 8, 5, 0, 200, 15)
              Call CustomMenuLabel(Index, 26, "Do Not Have Quest Item!", 3, 280, 8, 5, 0, 200, 15)
          End If
    End If
    Exit Sub

```
For some reason when I run this code, it just doesn't do anything. The first box opens, and when I click 'Accept Quest', nothing happens. It seems as if the server doesn't read the 'Clicked_Index' command. I have checked and then re-checked. This is so stupid, I mean how can a script run first and the same script not run the next day :( *sigh*

Please give me a hand
-Thanks in advance
Link to comment
Share on other sites

> Just wondering, do I have to 'call' the labels according to the index numbers? Like, call 1, then 2 then 3, etc… Or can I name all of them and the manu's can be called in any order.

The controls should be called in ascending order like 1, 2, 3, 4, 5, 6, etc.

Regards,
  Godlord.
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...