ID:261913
 
I'm having trouble with finding an obj in a global newlist. It always says "Party not found!" Any idea how to fix it? Here is what I have:
                partywho()
set category = "Party"
var/obj/parties/p
var/obj/parties/P
for(p in worldparties)
if(p.name == src.party)
P = p
if(P)
src << "<b><font color=#0033AA size=1>[src.party]</b></font>"
for(var/mob/M in P.members)
if(P in world)
src << "<font color=#0033AA size=1>\icon[M][html_encode(M)]([M.key]) Class: [M.class] Level: [M.level] Experience: [M.exp]/[M.maxexp]"
else
src << "<font color=#0033AA size=1> [M] (Currently Offline)"
else
src << "Party not found!"


Thanks in Advance,

Unknown Person <<
You have
if (p.name == src.party)

Question... did you actually set src.party equal to the name of the party, or to the party itself? One is a string of text, the other is an actual party obj.

It won't ever find any party whose name is equal to an obj!

Also, if you do have a var that's == to the party object, why search a list?

partywho()
if (src.party)
for (var/mob/m in src.party.members)
src << "Blah blah blah"
else
src << "You have no party."
In response to Hedgemistress
The mob var, party, is a text string.
In response to Unknown Person
Okay... well that just begs the question, "Why?"

Why have an obj type to represent parties and then make it so you have to go through this kind of perverse transformation each and every time you want to do anything with the information contained by the mob.party var?

If your goal is to add pointless processor cycles to your game at the expense of easy coding and easy functionality, you've found a great way to do it. There's really nothing you can accomplish having a text var for the party that you couldn't accomplish by having an actual reference to the obj.
If you insist on doing it this way, here's a shorter way to do it:

for (var/obj/parties/p in worldparties)
src << "[p.name] | [src.party]" //debugging line.
if (p.name == src.party)
party stuff here.
return

src << "No party found!"

If it's still not working, the debugging line should show you why by letting you see the exact names of each party in worldparties alongside the player var. Possibilities include, you haven't actually changed/set the name of the parties objs, so they're all called "parties", or you haven't added them to the worldparties list, so no text gets output at all, or if you're doing everything in a very manual fashion, there's just some typo or discrepancy between the two names.

Once fixed, remove the debugging line.

But unless there's some actually compelling reason to do it this way, don't. Just make the mob var party

mob/var/obj/parties/party

and be done with it.
In response to Hedgemistress
If they are references to mobs, you're going to want to make the party list a temporary variable so it doesn't get saved.
In response to Garthor
Good point. What I would tend to do, if parties are intended to be permanent/savable, is change the mob's party var to a text string, either the name or tag of the party, on save, and then search for a match when the mob loads... in which case a method for searching through parties can be handy, just not for the purpose this unknown person is trying to use it for.
OK, it is fixed. Thanks to whoever helped me.

Unknown Person <<
In response to Unknown Person
Unluckily, I stumbled up to another problem. The thing that's above works. I save the parties onto my savefile. They save properly, but when I use this, or something that checks for parties:
partywho()
set category = "Party"
if(src.party=="None") return
var/obj/parties/p
var/obj/parties/P
for(p in worldparties)
if(p == src.party)
P = p
if(P)
src << "<b><font color=#0033AA size=1>[src.party]</b></font>"
for(var/mob/M in P.members)
if(P in world)
src << "<font color=#0033AA size=1>\icon[M][html_encode(M)]([M.key]) Class: [M.class] Level: [M.level] Experience: [M.exp]/[M.maxexp]"
else
src << "<font color=#0033AA size=1> [M] (Currently Offline)"
else
src << "Party not found!"


It gives me "Party not found!". I'm not sure why this happens, because the party is obviously in the worldparties list.

Again, thanks if anyone could help me.

Unknown Person <<
In response to Unknown Person
Unless the worldparties list and all the player mobs are saved in one savefile with a single action, then upon reloading, the mob.party will -not- be in the worldparties list... instead, worldparties will have a separate list of identical copies of parties.

If it's necessary to save a mob's party AND a list of all parties independent of mobs, then your original approach (using names for the mob var) is one way to do it... the way I would suggest, though, is make mob.party a tmp var, give each party a unique .tag (can be the same as the party's name), have a non-tmp var that saves a text string equal to the .tag of their party, and when players rejoin,

mob.party = locate (mob.partytag)
Does worldparties really contain what you looking for? Are both the p.name and src.party vars the same type of var (text)? Are they really the same? (Capitalisation is important.)

You'd actually be far better off making the party var hold a reference to the object, rather than the name of the party.

<code>mob player var/obj/parties/party verb/partywho() if (party) for (var/mob/M in party.members) src << M else src << "You don't belong to a party."</code>
In response to Hedgemistress
Thanks, once again, Hedgemistress. :)

Unknown Person <<
In response to Unknown Person
Okay, this is starting to get annoying. I think this is the last question I'll ask. I hate to ask too many things... Here it goes.

When I save the list, it saves alright. I used the mob.party var as tmp, and made a partytag thing. It works. But, one problem. Everything is good and it finds the party in the worldparties list, but it doesn't save the variables in the party obj. How can I make it do that?

Thanks, again,

Unknown Person <<
In response to Unknown Person
Hmmmm... be more specific? What sort of variables does it not save? A list of mobs?

If so, you're still running into the same problem... when you've got a var or a list that contains an actual atom/object, it's going to save an exact copy of that object, and when you load it back up, it's going to load an exact copy of that object (probably floating around in null space so you can't see it), not the object itself.

The way to fix this would depend on what you want parties to do. If it's not important to be able to tell who's in your party but offline, just don't even try to save the list of party members... when a member logs back in, it finds the party, and you can add them back in at that point.

If it is important to be able to know who's in your party and offline, then we're back to more tmps and tags... each player would need a unique id for their tag (if you enforce unique names, that's one way to do it. The other is to have a playerid var, with a number that goes up each time a new character is made... don't forget to save the number).