[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Python
. . -> [Subject]  *cries* I try to make it work! lists again...

*cries* I try to make it work! lists again...

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Chronoti   USA  (27 posts)  [Biography] bio
Date Mon 15 Dec 2003 09:04 PM (UTC)
Message
Alright!! Here we go! Now posted previously, if I want to make a global list, I need to put it in a script file, and in a function within that file, no problem right? Just for a test I did exactly that.

def newList(name, output, wildcs):
global list

I put that in a file called "game.pys", now I made it so the main script file calls that file, and yes its using python... now to call this lets say via an alias... I created the alias named the alias "tst", and put in the action of it: newList()

well I tried to invoke it, and i got "needs 3 parameters" why does it need params? Can I make the function without params, or what should i do to use functions with python in mushclient? Thanks!
[Go to top] top

Posted by Chronoti   USA  (27 posts)  [Biography] bio
Date Reply #1 on Mon 15 Dec 2003 10:44 PM (UTC)
Message
ok ok, maybe I am going about it wrong, in fact on the other board, talking about splitting and rejoining variables etc... I thought about it, and started doing that.. ok here is what i got


string = world.getVariable("test")

string2 = string.split(":")

world.note( "Variable has been split" )

string2.append( "test?" )

delim = ":"

delim.join ( string2 )

string2 = str( string2 )
world.setVariable("test", string2)


the alias is "test.add", now when I do that, lets say the variable is empty, after i do that, it ends up having this value: [u'', 'test?']

what the hell is that? anyways (I did try it without forcing it to str() all I got was alot of errors).

I know i am doing alot of this wrong, I just need a bit of help... Thanks.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #2 on Tue 16 Dec 2003 11:35 AM (UTC)
Message
Pretty confusing... can you go back to the first post in this thread and post the alias you used for testing? Just hit Copy in the aliases dialogue, with the needed alias selected, and paste it here. My guess is that you use the 'Send to script' option and are trying to call a function that expects 3 arguments without passing it any, but I can't say for sure without seeing the actual alias.
[Go to top] top

Posted by Chronoti   USA  (27 posts)  [Biography] bio
Date Reply #3 on Tue 16 Dec 2003 04:43 PM (UTC)
Message
lol, actually I um, didn't get that to work, but i did get variables to work in python (splitting/joining) after a bit of a struggle. ok all I did in the alias was this.


newList()


thats all, just to test if it worked... *shrugs* Is that the wrong way to call a function in mushclient?
[Go to top] top

Posted by Shadowfyr   USA  (1,786 posts)  [Biography] bio
Date Reply #4 on Tue 16 Dec 2003 05:34 PM (UTC)
Message
Umm. You should drop the (). I am not sure how Mushclient handles calls, but technically using newList() would imply that you are calling that function/procedure without any arguements. Since Aliases and Triggers attempt to automatically add three arguements, you are giving it contradictory information. I don't know if this is actually the problem though.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #5 on Tue 16 Dec 2003 07:01 PM (UTC)
Message
Heh, still says nothing. Where did you put that line? There are 2 ways to call a function in Mushclient and there's no way to tell which one you used, hence why I asked to post the actual alias.

And using MC variables as lists might be a good idea in Vbscript (since Vbscript lacks lists, as well as many other things) but using them that way in Python is strange, to say the least, as Python has lists of its own and they work fine.
[Go to top] top

Posted by Chronoti   USA  (27 posts)  [Biography] bio
Date Reply #6 on Wed 17 Dec 2003 04:11 AM (UTC)
Message
....


OK!!!! Here it is once more..


I press the keys: CTRL+SHFT+9 (opens up the alias window)

I click on "Add", type "test" where it says "Alias", where it says "send" i type: newList() (now I changed it to newList but still nothing).

Now, where it says "Send to: " I put "script" also changed it back to "world" but still nothing worked.


OK! maybe thats a clearer picture of how I called that function... *shrugs*


PS Sorry if it sounds rude, just a really bad day.. yup...
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #7 on Wed 17 Dec 2003 02:25 PM (UTC)
Message
That at least confirms my original guess. You are calling the function that expects to recieve 3 arguments without giving it any. The way you have your function declared in the script file, you can use a simpler way of calling it from Mushclient. Simply put 'newList' into the Script field, set the 'Send to' to 'World', and delete whatever is in the Send field. Mushclient will add the needed arguments itself.

P.S. Try copying and pasteing aliases and triggers using the instructions I gave in my first reply. Providing exact details of your triggers/aliases/timers gets you better help, faster.
[Go to top] top

Posted by Chronoti   USA  (27 posts)  [Biography] bio
Date Reply #8 on Thu 18 Dec 2003 05:11 AM (UTC)
Message
I apologize for that Ked, thanks for your help... I didn't even see a copy button, now I do, ugh... Now I am moving along slowly but now understanding. *bows to master* Sorry sensai...
[Go to top] top

Posted by Chronoti   USA  (27 posts)  [Biography] bio
Date Reply #9 on Thu 18 Dec 2003 05:30 AM (UTC)
Message
Found a new one here! Now here is the script right out of the editor


def addOne(thename, theoutput, wildcards):
global list
list.append("test?")
world.note( len(list) )

def createList(thename, theoutput, wildcards):
global list
list = []


no problem, its beautiful... anyways... thats not the point *cough*

just testing it out for now... ok, lets say, ya see the one that says "addOne"? how would It be possible in mushclient to call that in an alias, but use what I want it.er... crap hold on..


Lets say, I have a trigger... It triggers off of "druid", "wolf", and... "hobbit" or something. Now, when i hit druid, wolf or hobbit, I want to be able to add it to the list, without having to make a function for each and every one of those creatures (the list will get huge)... How could I just addOne(something, something, bear?) hrm, I dunno, So far its all working out nicely... And I do appreciate the much needed help. Thanks again Ked.
[Go to top] top

Posted by Chronoti   USA  (27 posts)  [Biography] bio
Date Reply #10 on Thu 18 Dec 2003 05:52 AM (UTC)
Message
*sigh* I feel retarded, scratch that.


OK! Here it the problem, I fixed the above one.. but here is thisssss one.


Now how can I access the actual list from within other scripts, yes I made it global in the top of the function for each function... but when I try to access it in another function, it shows the list to be empty.

Anyways... here it is in plain english.


I have a function that creates the list (i only invoke this one time) The second function just adds a few thing to the list, and the third one should grab the first item out of the list, but the list is empty on the third function (thats what it is showing me anyways).


So anyways... help?
[Go to top] top

Posted by Nick Gammon   Australia  (22,982 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Thu 18 Dec 2003 06:57 AM (UTC)
Message
I suggest reproducing the problem in a minimal number of lines of code and post the actual code. That way we can try it. Description of code are not usually as useful as actually seeing it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Chronoti   USA  (27 posts)  [Biography] bio
Date Reply #12 on Thu 18 Dec 2003 03:34 PM (UTC)
Message
Script file:

def addOne(items):
global list
list.append("test?")



def createList(thename, theoutput, wildcards):
global list
list = []

def showList():
global list
world.note(list[0])


I have an alias, to create a list, (which I call 1 time), an alias to add to the list ( i just call this alot to make the list), and then one to show the first item of the list..
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #13 on Thu 18 Dec 2003 05:58 PM (UTC)

Amended on Thu 18 Dec 2003 06:00 PM (UTC) by Ked

Message
Ok, first of all... Why are you using an alias to create the list? You can do it automatically by placing the contents of your 'createList' function (actually only the second line, since you don't need to declare variables in Python, just to initialize them) outside any function definitions. With that amendmend your script would look like this:


list = []

def addOne(items):
  global list
  list.append("test?")

def showList():
  global list
  world.note(list[0])



Here's what I used to test your script. I've made 2 aliases, one calling the 'addOne' function and passing it's single wildcard to it, the other calling the 'showList' function without any arguments. Both aliases 'Send to script', you can import them into Mushclient by copying there text here and then hitting Paste in the alises dialogue in Mushclient:


<aliases>
  <alias
   match="^test (\d+)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>addOne(&quot;%1&quot;)</send>
  </alias>
  <alias
   match="show"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>showList()</send>
  </alias>
</aliases>


Then I changed your 'addOne' function a little to demonstrate how arguments are passed into functions and used inside them. Here's the final version of your script:


list = []

def addOne(items):
    global list
    list.append(items)

def showList():
    global list
    world.note(list[0])


Note that the only change from the above version is the line 'list.append(items)' in the 'addOne' function. I have 'items' instead of 'text?'. Since the word 'items' appears in the parenthesis after the function's name, it is the variable holding an argument that needs to be passed to the function when calling it, and inside the function's body that same name refers to the same argument. To test this, simply copy both aliases and replace your script with this one, and then do:

test 100
show

in Mushclient. That should display '100' in your output window.
[Go to top] top

Posted by Chronoti   USA  (27 posts)  [Biography] bio
Date Reply #14 on Sat 20 Dec 2003 04:13 PM (UTC)
Message
alright, thanks ked, it works perfectly. At any rate, everything is working, and I'm experimenting, *smiles* Thanks again Ked for being patient and helping. (i'll post the finished script here somewhere)
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


26,624 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]