Server Help

ASSS Questions - Globalizing Strings in python

BDwinsAlt - Sun Jul 09, 2006 9:43 pm
Post subject: Globalizing Strings in python
Yea It seems python is a bit different when it comes to globalizing strings.
I put captain = "None" at the top of my python file, later on when someone types ?cap I make it do captain = p.name.

I made it send a message with the captain name in the same def.
Then I use my command to view the current captain and it resets to none.

How can I globalize strings easily in asss?


****EDIT:****
I thought I figured it out but it was per player. I need to make it do it arena wide.
Chambahs - Mon Jul 10, 2006 12:22 am
Post subject:
Posting the code would help me out to figuring out the problem.
xsp0rtsfanx - Mon Jul 10, 2006 12:27 am
Post subject:
he had it up but he figured it out
BDwinsAlt - Mon Jul 10, 2006 1:14 am
Post subject:
I had it up but it was only for that player. I need to make it arena wide. The code is on my vmware so copying and pasting is hard. Anyways it's a pretty simple question, how do you globalize a string for a module?

Code: Show/Hide

def c_cap(cmd, params, p, targ): <-- notice no arena
    arena.sd_captainA = p.name


How can I make it so arena is added with this. Arena won't work when adding it to that def. Any way around this. I can't do another def like

Code: Show/Hide

def cap(arena):
   arena.sd_captainA = p.name  <--notice no p defined either.


What can I do?
BDwinsAlt - Mon Jul 10, 2006 5:35 am
Post subject:
FIXED!

I decided to use p.arena.sd_captainA.
It works. It only works in sub-arenas but I was gonna make it a squad duel thing anyways. It's only in ?go sd.

So everything works. For those who are new like me I will show you the code.

Python's way of globalizing strings is a lot different from java and C++, you can't just stick the string at the top of the source.

Code: Show/Hide

    p.arena.sd_captainA = p.name


I didn't post the full code because its too long and not needed.
So I seem to slowly be learning the way asss works with python.

Wish me luck!
Smong - Mon Jul 10, 2006 10:58 am
Post subject:
I think if you want to modify globals you need to make them lists, otherwise they are read only.
See: http://forums.minegoboom.com/viewtopic.php?p=29060#29060

You should stick with storing data in the arena object, since a zone can have many arenas open at once, you wouldn't want a captain in one arena to have control over all the arenas they aren't even in.
BDwinsAlt - Mon Jul 10, 2006 7:14 pm
Post subject:
Im not really sure on how to put players into a list in python. I was not aware strings were read only. What I am doing is a squad duel plugin so I need two people to be captains upon them typing ?cap. I'm reading the example of lists on some website.


Code: Show/Hide

3.3 Mutability

Python data structures are either mutable (changeable) or not. Strings are not mutable - once created they cannot be modified in situ (though it is easy to create new, modified versions). Lists are mutable, which means lists can be changed after being created; a particular element of a list may be modified. Either single elements or slices of lists can be modified by assignment:

    >>> x
    [1,4,9,'new end of list']
    >>> x[2] = 16
    >>> x
    [1,4,16,'new end of list']
    >>> x[2:3] = [9,16,25]
    [1,4,9,16,25,'new end of list']


I am guessing I can use p.arena.sd_captainA = [p.name] ???
This kind of thing is making me lean towards C.
Muskrat - Mon Jul 10, 2006 9:29 pm
Post subject:
Java Strings are immutable as well, nothing new there.

Probably shouldn't just use the name anyways though.
BDwinsAlt - Mon Jul 10, 2006 10:22 pm
Post subject:
I want to be able to change the captainA and captainB. Is that supose to be hard.

Hmm this might be some help for me. I don't want to open up vmware if this isn't gonna work but im gonan try http://skunkweb.sourceforge.net/PyDO/node17.html
Smong - Tue Jul 11, 2006 10:15 am
Post subject:
Sorry if I confused you, your original code was correct:
Code: Show/Hide
arena.sd_captainA = p.name

Even if strings are immutable you can still assign values to arena.sd_captainA as many times as you like.
BDwinsAlt - Tue Jul 11, 2006 6:59 pm
Post subject:
LOL. Ok good. I was like wth. I spent forever trying to figure it out. Thanks for letting me know. Smong your always cool with me. Thanks.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group