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!
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
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.
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?
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.
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.
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.
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...
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.
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).
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.
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..
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:
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.
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)