XenoBot Forums - Powered by vBulletin

User Tag List

View Poll Results: What's your opinion?

Voters
3. You may not vote on this poll
  • Yes, it's nice idea

    1 33.33%
  • No! It's low. Better learn programming.

    2 66.67%
Results 1 to 7 of 7

Thread: [LUA] io.read()

  1. #1

    Join Date
    Aug 2013
    Posts
    24
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    [LUA] io.read()

    I need a lua function like std::cin in C++ or Console.WriteLine(); in C#
    Why?
    Because it will be much easier to do auto-config scripts or something like that. I give you an example:

    Code:
    ...
    
    Config:SendOrangeMessage("Config creator", "Name of script.")
    answer1 = io.read()
    File:write("--" .. answer1 .. "--")
    Config:SendOrangeMessage("Config creator", "Tell me your main bp.")
    answer2 = io.read()
    File:write("Mainbp = \"" .. answer2 .. "\"")
    Config:SendOrangeMessage("Config creator", "Tell me your Loot bp.")
    answer3 = io.read()
    File:write("Lootbp = \"" .. answer2 .. "\"")
    
    ...

  2. #2

    Join Date
    Feb 2014
    Posts
    117
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    There is already Channel.New()
    By it you can edit any config.lua as much as you want.

  3. #3

    Join Date
    Aug 2013
    Posts
    24
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Ohh... I really wanted to write this more specifically but it doesn't work i see..

    I don't need Channel.New() function. I need function which will be waiting for my typing and didn't check it what i type. I think that this simple function can make some scripts very much easier to write. So why not?

    Channel.New() can that but only if i do something like that:

    Code:
    ...
    if (talkstate == 0) then
    ...
    
    Config:SendOrangeMessage("Config creator", "Name of script.")
    talkstate = 1
    
    elseif ((talkstate == 1) and (answer == "config")) then
     File:write("--" .. answer .. "--")
    Config:SendOrangeMessage("Config creator", "Tell me your main bp.")
    talkstate = 2
    elseif ((talkstate == 2) and (answer == "backpack")) then
     File:write("--" .. answer .. "--")
    Config:SendOrangeMessage("Config creator", "Tell me your Loot bp.")
    talkstate = 3
    elseif ((talkstate == 3) and (answer == "beach backpack")) then
    ...
    And my answer can't be random.

  4. #4
    Moderator shadowart's Avatar
    Join Date
    Dec 2014
    Location
    Sweden
    Posts
    1,985
    Mentioned
    225 Post(s)
    Tagged
    3 Thread(s)
    You can write a sort of bastardized version that waits a fixed amount of time for the user to write something and then return whatever was written. Alas the real version that waits for the user to type and then returns instantly (with optional timeout) would require preemptive multitasking which isn't supported by Lua and would be one hell of a hassle to implement. I really doubt that this is something that the devs would like to spend time on.

  5. #5

    Join Date
    Mar 2014
    Posts
    60
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Code:
    local talkstate = 0
    
    function onSpeak(channel, message)
       --Send Messages
       if message == "walker" then
    	talkstate = 1
    	return true
        elseif message == "looter" then
    	talkstate = 2
    	return true
        elseif message == "target" then
    	talkstate = 3
    	return true
        end
        if(talkstate == 1) then
    	File:write("WPT: " .. message .. "--")
    	channel:SendOrangeMessage('', message .. 'Added as the answer.')
        elseif (talkstate == 2) then
    	File:write("LOOTER: " .. message .. "--")
    	channel:SendOrangeMessage('', message .. 'Added as the answer.')    
        end
    
    end
    
    
    function onClose(channel)
    	print('Draky Casino closed. Go to Scripter and open it again if you want to use me.')
    end
    
    local canal = Channel.Open('canal', onSpeak, onClose)
       if talkstate == 0 then
    	canal:SendOrangeMessage('canal', 'Options: Walker, Looter, Target')
       end
    this check the talkstate and write in correct lin

  6. #6
    Administrator
    Join Date
    Dec 2010
    Posts
    2,565
    Mentioned
    228 Post(s)
    Tagged
    1 Thread(s)
    When you create a custom channel in Xenobot you pass the constructor three parameters: channelName, textCallback, closeCallback.

    The first is a string and is the name given to the channel you create. The last is a function that is called when the channel is closed.

    The second, which is relevant to what you're looking for, is called any time any text is sent in the channel. It looks something like this:

    Code:
    function OnSpeak(channel, message)
       if (message == "ping") then
          channel:SendOrangeMessage("Channel", "Pong!")
       end
    end
    
    function OnClose() end --empty
    
    local newChannel = Channel.New("Channel", OnSpeak, OnClose)
    
    newChannel:SendOrangeMessage("Channel", "Hi!")

  7. #7
    Moderator shadowart's Avatar
    Join Date
    Dec 2014
    Location
    Sweden
    Posts
    1,985
    Mentioned
    225 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Spectrus View Post
    When you create a custom channel in Xenobot you pass the constructor three parameters: channelName, textCallback, closeCallback.

    The first is a string and is the name given to the channel you create. The last is a function that is called when the channel is closed.

    The second, which is relevant to what you're looking for, is called any time any text is sent in the channel. It looks something like this:

    Code:
    function OnSpeak(channel, message)
       if (message == "ping") then
          channel:SendOrangeMessage("Channel", "Pong!")
       end
    end
    
    function OnClose() end --empty
    
    local newChannel = Channel.New("Channel", OnSpeak, OnClose)
    
    newChannel:SendOrangeMessage("Channel", "Hi!")
    Considering his code examples I'm pretty sure he already knows that but finds it cumbersome to use as you have to turn your callback function into a finite-state machine.
    Last edited by shadowart; 02-17-2015 at 03:07 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •