Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
emnaki
Wanderer


Joined: 12 May 2007
Posts: 59

PostPosted: Thu Jan 24, 2008 11:42 am   

reading user input in a LUA script
 
I can't seem to figure out how to get the user input via LUA in C-MUD, I've tried the below function:
Code:

function getinput()
   print("Enter part:")
    input = io.stdin:read()
   print(input.." received")
end

But it does not seem to work. Is it even possible to do it?
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Thu Jan 24, 2008 1:02 pm   
 
You could make a call to the CMUD prompt command, maybe?
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Thu Jan 24, 2008 2:22 pm   
 
For a single parameter use: zs.param() or zs.param(number of the parameter that you want) or zs.param(-1) to get all of them.
For multiple parameters use: zs.params() to get them all or zs.params(n) to get all of them starting at position n or if you want to be contrary zs.params(-n) to get only the one at position n.

In my opinion the best way to pull out the parameters into a usable form is to place them into a table using the following.

local list = {}
for i=1, zs.numparam do
list[i]=zs.param(i)
end

Edit: I misread the question sorry.

At the moment I am thinking that you create an oninput trigger that you turn on from within the lua function.

Something like.
#oninput {(*)} {#noinput;input=%1}

Then use zs.var.input() in your script. Sorry I'm in a hurry cannot go into it further. Perhaps Fang already knows how to do this strait from within Lua sans the trigger.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu Jan 24, 2008 5:05 pm   
 
Why me? :(

But yeah, I do. io.read() won't work because the command line isn't linked to stdin, but you can use zs.func.prompt() in exactly the same way, like Larkin suggested.

something = zs.func.prompt()

The only way to get stuff from the command line is with an oninput trigger - you can use Lua code in the trigger script itself.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net