A wierd error

05/21/2010 11:14 2010mrsurfer#1
Okay i made a npc yesterday and Arco gave me tthe line of code to make it so you can only get it once a day but the source wont debugg now,
Loc.X = ushort.Parse(Info[5]); this line of code comes up in yellow when it debuggs and i dont know how to fix it, it also says: Index was outside the bounds of the array. Anybody know what this is?
05/21/2010 11:38 xScott#2
Quote:
Originally Posted by 2010mrsurfer View Post
Okay i made a npc yesterday and Arco gave me tthe line of code to make it so you can only get it once a day but the source wont debugg now,
Loc.X = ushort.Parse(Info[5]); this line of code comes up in yellow when it debuggs and i dont know how to fix it, it also says: Index was outside the bounds of the array. Anybody know what this is?
"Index was outside the bounds of the array"

Means the number of array your trying to assign something to is larger then the one defined

Like an array with 5 Elements, and you try and assign something to Element 6, which doesn't exist, thats why its giving you an error
05/21/2010 12:08 2010mrsurfer#3
Quote:
Originally Posted by xScott View Post
"Index was outside the bounds of the array"

Means the number of array your trying to assign something to is larger then the one defined

Like an array with 5 Elements, and you try and assign something to Element 6, which doesn't exist, thats why its giving you an error
Do you know how to fix this?
05/21/2010 12:29 pro4never#4
Quote:
Originally Posted by 2010mrsurfer View Post
Do you know how to fix this?
Easy, either modify the input (file or thing being read), modify the reader (change how many things aee trying to be read or more likely, check your input values.


I'm assuming this is related to an npc spawn code loaded from a text file? Go through them and ensure none of the entries are messed up/incomplete.
05/21/2010 12:33 2010mrsurfer#5
Quote:
Originally Posted by pro4never View Post
Easy, either modify the input (file or thing being read), modify the reader (change how many things aee trying to be read or more likely, check your input values.


I'm assuming this is related to an npc spawn code loaded from a text file? Go through them and ensure none of the entries are messed up/incomplete.
Well i added my npc in npcdialog.cs, code:
case 987787:
{
if (Control == 0)
{
GC.AddSend(Packets.NPCSay("Hello, you can get 50k cps free each day!"));
GC.AddSend(Packets.NPCLink("Yes please", 2));
GC.AddSend(Packets.NPCLink("No Thanks.", 255));
GC.AddSend(Packets.NPCSetFace(N.Avatar));
GC.AddSend(Packets.NPCFinish());
}
if (Control == 2)
{
if (!GC.MyChar.CPDay)
{
GC.AddSend(Packets.NPCSay("Here you go, remember to say thank you to Jon"));
GC.MyChar.CPs += 50000;
GC.MyChar.CPDay = true;
GC.AddSend(Packets.NPCLink("Thank You Jon", 255));
GC.AddSend(Packets.NPCSetFace(N.Avatar));
GC.AddSend(Packets.NPCFinish());
}
else
{
GC.AddSend(Packets.NPCSay("You have already claimed your cps for the day."));
GC.AddSend(Packets.NPCLink("Oh sorry.", 255));
GC.AddSend(Packets.NPCSetFace(N.Avatar));
GC.AddSend(Packets.NPCFinish());
}
}
break;
}
#endregion


And then Arco told me to put this into chracter.cs : public bool CPDay;

Under: public bool alive
05/21/2010 12:59 xScott#6
Quote:
Originally Posted by 2010mrsurfer View Post
Well i added my npc in npcdialog.cs, code:
Code:
case 987787:
{
if (Control == 0)
{
GC.AddSend(Packets.NPCSay("Hello, you can get 50k cps free each day!"));
GC.AddSend(Packets.NPCLink("Yes please", 2));
GC.AddSend(Packets.NPCLink("No Thanks.", 255));
GC.AddSend(Packets.NPCSetFace(N.Avatar));
GC.AddSend(Packets.NPCFinish());
}
if (Control == 2)
{
if (!GC.MyChar.CPDay)
{
GC.AddSend(Packets.NPCSay("Here you go, remember to say thank you to Jon"));
GC.MyChar.CPs += 50000;
GC.MyChar.CPDay = true;
GC.AddSend(Packets.NPCLink("Thank You Jon", 255));
GC.AddSend(Packets.NPCSetFace(N.Avatar));
GC.AddSend(Packets.NPCFinish());
}
else
{
GC.AddSend(Packets.NPCSay("You have already claimed your cps for the day."));
GC.AddSend(Packets.NPCLink("Oh sorry.", 255));
GC.AddSend(Packets.NPCSetFace(N.Avatar));
GC.AddSend(Packets.NPCFinish());
}
}
break;
}
#endregion
And then Arco told me to put this into chracter.cs : public bool CPDay;

Under: public bool alive
that looks like it should work o-o, whats wrong with it? + use the code format when posting code, makes it neater :)
05/21/2010 13:03 2010mrsurfer#7
Quote:
Originally Posted by xScott View Post
that looks like it should work o-o, whats wrong with it? + use the code format when posting code, makes it neater :)
I dont know whats wrong with it, this line of code is the problem :( :
Loc.X = ushort.Parse(Info[5]);
05/21/2010 13:25 xScott#8
Quote:
Originally Posted by 2010mrsurfer View Post
I dont know whats wrong with it, this line of code is the problem :( :
Loc.X = ushort.Parse(Info[5]);
Like Pro4Never said, Looks like you put dodgy Coordinates when you inserted this npc in the NPC.Txt, change the coordinates of the NPC and see if that works
05/21/2010 13:48 2010mrsurfer#9
Quote:
Originally Posted by 2010mrsurfer View Post
I dont know whats wrong with it, this line of code is the problem :( :
Loc.X = ushort.Parse(Info[5]);
Quote:
Originally Posted by xScott View Post
Like Pro4Never said, Looks like you put dodgy Coordinates when you inserted this npc in the NPC.Txt, change the coordinates of the NPC and see if that works
Ahhh i think i know why, I havent put the Coordinates in for that npc yet xD could this be the problem??
05/21/2010 17:19 xScott#10
Quote:
Originally Posted by 2010mrsurfer View Post
Ahhh i think i know why, I havent put the Coordinates in for that npc yet xD could this be the problem??
Yep, looks like it.
put them in and tell me if it works :D
05/21/2010 22:28 2010mrsurfer#11
Yep it works :D silly error of me xD but ill learn :P Thanks
05/21/2010 23:00 xScott#12
Quote:
Originally Posted by 2010mrsurfer View Post
Yep it works :D silly error of me xD but ill learn :P Thanks
Nice to know :]
05/21/2010 23:28 2010mrsurfer#13
:) since u helped i pressed thanks
05/22/2010 17:33 pro4never#14
Quote:
Originally Posted by 2010mrsurfer View Post
Ahhh i think i know why, I havent put the Coordinates in for that npc yet xD could this be the problem??
Glad you got everything working.

Just for some further explanation. That error just means you are trying to load something that isn't there...

Think of it this way.

You load things out of the file and separate them using spaces. using [] you can recall which entry you want to use. If there is nothing in that entry though it means there is nothing to load so it has no idea what to do after that.


Also: I wanna point out a problem with your npc. Relogging will reset the bool back to true meaning players can claim it again. You will want to add a time claimed entry... something along the line of

public static DateTime DailyClaimed;


Then you will want to A: have it save to database when claiming and B: load from database when logging in.

Then in the npc do something like...

if (DateTime.Now > GC.MyChar.DailyClaimed.AddHours(24))
{
claim code
GC.MyChar.DailyClaimed = DateTime.Now;
Update Character database.
}
else
{
can't claim code
}


Anyways, it's not urgent but I figured I'd mention it seeing as it may be useful to you later.

Good luck.
P4N
05/27/2010 15:37 2010mrsurfer#15
Thanks P4N :)