Full Version : xmlsocket question
xmlspawner >>Q&A >>xmlsocket question
<< Prev | Next >>
slida- 05-31-2006
Well this sent me on an interesting but ultimately failed quest because I'm using windows 98. The console command was ignored(or perhaps not ignored but it had no effect) no matter where I put it in the code(I changed it print a string to see if I could get it to work). I realized I probably needed the SDK and downloaded it, and decided I would just start teaching myself C#, but it won't work with 98. I tried SharpDevelop, and it installed fine but wouldn't run(it said it couldn't find the OpenConsole something something in kernel32.dll or something like that.) So then I went the forums over there, but there was no way to join up, or ask to join up, so nothing. Until I upgrade I'm just gonna have to try and figure things out little by little. I can at least make code that compiles now, even if it doesn't do anything.
All I really need now to solve this part of the problem is the proper way to code this

CODE
if(socket0.isaugmented && socket1.isaugmented && socket2.isaugmented && socket3.isaugmented)

This should do the trick because there is only one order now in which the augments can be placed.
Thanks for all your help, I really didn't know in advance how much coding was going to be required to implement my ideas, although I suppose it's not too complex if you know what you are doing, and I'm starting to pick it up a bit. OOP is still a bit perplexing to read with my very basic knowledge of how it works and syntax is a real problem for me.
ArteGordon- 06-01-2006
You dont need to install the SDK or anything like that, and it is not a win98 issue.
If you didnt see anything displayed on the console, it was because it never got to that point.
When the server starts up, all of the messages that you see in the console window are generated by Console.WriteLine calls.
If you just want to test to see how many sockets are free (not augmented)

CODE
if(s.NFree == 0) { // then it is filled up }

slida- 06-01-2006

QUOTE
If you didnt see anything displayed on the console, it was because it never got to that point. When the server starts up, all of the messages that you see in the console window are generated by Console.WriteLine calls.

This is what I first assumed, I've figured out the whole thing finally this morning, the reason I went through so much trouble was because I assumed since the statue was augmenting, my onAugment method was being used and I put Console.WriteLine in every possible place. Turns out it was completely ignoring the code altogether cause I tried to do that overload thing. Figured it out by putting it in the CanAugment method. If only I'd tried that sooner...
Even though I'm going to just do a simple check now, I am still curious as to what was wrong with the other code heres what I've discovered:

CODE
for (int i = 0; i<s.SocketOccupants.Count; i++) { XmlSockets.SocketOccupant so = (XmlSockets.SocketOccupant)s.SocketOccupants[i]; if(so == null) continue; none of the code is executed after this line.

This wasn't the case with the original foreach thing you gave me, it worked fine. I though maybe so != null now so I deleted the line and got the null-object reference again.
ArteGordon- 06-01-2006
the foreach and the for loop do exactly the same thing. The only difference is that with the for loop you also have the index 'i' of the socket being referenced.
It must be something else.
slida- 06-01-2006
Okay, I'm learning a bit on how to explain problems, here's the situation:
This code yields check check check check on the console

CODE
for (int i = 0; i<s.SocketOccupants.Count; i++) { XmlSockets.SocketOccupant so = (XmlSockets.SocketOccupant)s.SocketOccupants[i]; Console.WriteLine("check"); if(so == null) continue;

This code does nothing to the console.

CODE
for (int i = 0; i<s.SocketOccupants.Count; i++) { XmlSockets.SocketOccupant so = (XmlSockets.SocketOccupant)s.SocketOccupants[i]; if(so == null) continue; Console.WriteLine("check");

so the problem must be right here:

CODE
for (int i = 0; i<s.SocketOccupants.Count; i++) { XmlSockets.SocketOccupant so = (XmlSockets.SocketOccupant)s.SocketOccupants[i]; if(so == null) continue;

This just loops 4 times and doesn't go to the rest of the code.
ArteGordon- 06-02-2006
what method is this code in?
That should only happen when the sockets are empty.
slida- 06-02-2006

CODE
public override bool OnAugment(Mobile from, object target) { if(((SimpleArtifact)target).Name == "DEMISE") { // look for the other augments in the target sockets
XmlSockets s = ((XmlSockets)XmlAttach.FindAttachment(target, typeof(XmlSockets)));
if(s != null && s.SocketOccupants != null)
{
bool hasaugment1 = false;
bool hasaugment2 = false;
bool hasaugment3 = false;
bool hasaugment4 = false;
for (int i = 0; i<s.SocketOccupants.Count; i++)
{
XmlSockets.SocketOccupant so = (XmlSockets.SocketOccupant)s.SocketOccupants[i];
Console.WriteLine("check");
if(so == null) continue;
Console.WriteLine("check");
if (so.OccupantType == typeof(JimsRuby) && i == 1)
hasaugment1 = true;
if (so.OccupantType == typeof(JimsSkull) && i == 0)
hasaugment2 = true;
if (so.OccupantType == typeof(JimsEmerald) && i == 2)
hasaugment3 = true;
if (so.OccupantType == typeof(JimsCrystal) && i == 3)
hasaugment4 = true;
}
if (hasaugment1 && hasaugment2 && hasaugment3 && hasaugment4)
{
Mobile m = new Daemon();
m.MoveToWorld(from.Location,from.Map);
}
}
}
return true;
}

Now the other code worked and the Daemon spawned and the only real difference between that code is for(i etc.) and XmlSockets.SocketOccupant so = (XmlSockets.SocketOccupant)s.SocketOccupants[i]; have been substituted for foreach... so in s.socketoccupants. That's why I keep speculating about the difference between for and foreach and how it is handled.