Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal

Molinko

Members
  • Content Count

    451
  • Joined

  • Last visited

  • Days Won

    35

Posts posted by Molinko

  1. I would recommend using strictly local variables. Your problem is coming from the fact that the variables _rpx and _rpy are expected to be global but are only initialized in the 'printBack' function.

    This is a problem for the definition of 'readUrl' above that which expects _rpx and _rpy to be able to do its job. I believe a simple fix would be this....

    I think this is your issue... Im afraid i haven't had the chance to test. Good luck

    I was stupid.. Your problem is on line #52.

    term.setCursor(rpx, rpy)

    should be

    term.setCursor(_rpx, _rpy) -- you named the variables with underscores

    Hope that helps... :/

  2. I would recommend not executing strings sent down a network.. If you're just in a SP world then fine, have at it. But, if you're on multiplayer then this is a big security problem. Just saying..

    A better solution would be to design commands / responses with parameters that can be sent between the client and server. i.e.

    -- # On the server
    
    -- # Other code implied up hurr...
    
    local commands = {
    	openIris = function()
    		if s.irisState() ~= 'offline' then
    			m.send( f1, 20, 'Opening Iris.' )
    		end
    	end,
    	dial = function( address )
    		if s.irisState() == 'idle' then
    			m.send( f1, 20, string.format( 'Dialing %s', address )
    		end
    	end
    	-- ... more commands go here
    }
    
    -- # on message...
    -- # cmd should look like: { 'dial', 'kjai2sdiwdSOME_ADDRESSksjdlaks' }
    local cmd = { string.match( message1, '(%a%d_)' ) }
    
    local command, args = table.remove( cmd, 1 ), { table.unpack( cmd ) }
    
    -- # This calls our command with any args sent with it. This is safer than load('msg') because 'msg' could be malicious.
    commands[ command ]( table.unpack( args ) )
    
    -- # DISCLAIMER: I haven't run this code. Could have bugs. But this is generally how I handle commands over the net.

     

    Let me know if I need to clarify anything... :)

  3. I think this is what you mean...?

    local term = require 'term'
    local component = require 'component'
    local gpu = component.getPrimary 'gpu'
    
    --          text                   color          palette color? (true or false) (optional)
    -- Takes ( 'some string to color', number_color, [isPaletteColor] )
    local function cWrite( text, fgc, pIndex )
    	local old_fgc, isPalette = gpu.getForeground()
    	pIndex = ( type( pIndex ) == 'boolean' ) and pIndex or false
    	gpu.setForeground( fgc, pIndex )
    	write( text )
    	gpu.setForeground( old_fgc, isPalette )
    end
    
    -- Usage:
    cWrite( 'Hello colorfully', 0x2E86C1 )
    
    -- Or with a palette color..
    cWrite( 'Hello colorfully', 1, true )

     

  4. event.listen works like this.... 

    -- your handler
    local function doOnEvent(event, ...)
    	print( event, ... )
    end
    
    -- pass handler to event.listen to be called when there is a 'key' event.
    -- It will recieve the event and any other pertinent parameters like which key was pressed.
    event.listen( 'key', doOnEvent )
    
    -- Pass event.ignore your previously registered handler to stop it from passing any future event when we're done.
    event.ignore( 'key', doOnEvent )

    My point is that event.listen( 'someEvent', handler ) will be called even after your program has ended. So, if you were experimenting with it and registered a handler that prints an event

    then perhaps that is the result you're seeing printed to the screen. The wiki says that if your program registers a handler and your program calls event.pull, both will get the relevant event.

    Hence why your program may still be printing although you're only pulling an event... I hope this helps... If not.. kill it with fire and make a new one :)

  5. For your first question, you're spot on.

    Var args are passed like a function to a program. I'm not sure if they're all strings and/or numbers.. You might have to parse em.. Try something like this..

    local args, opts = shell.parse(...)

  6. When prototyping libs its helpful to put this at the top of your script to reload a specific library loaded with require.

    _G.packages.loaded["myLibFileName"] = nil

    -note the file name is extension less,

    And should be used before your call to require your lib.

  7. This would be my implementation of my suggestion... Just for shits..

    local players = {}
    for _, name in pairs(acceptableEntities) do
      players[name] = name
    end
    
    local function isValid(name)
      return players[name] and true or false
    end
    
    while true do
      local _,_,x,y,z,entity = event.pull("motion")
      if math.abs(x)<= tonumber(range) and math.abs(y)<= tonumber(range) and math.abs(z)<= tonumber(range) then --if recieved motion was within range
          if isValid(entity) then -- entity will always be a string. So will program arguments
            redstone.setOutput(side,15)
            os.sleep(stayOpen)
            redstone.setOutput(side,0)
            break --no need to continue testing if one is valid
          end
      end
    end 

    I just saw that you made an update while i was mid-post. Almost what I was thinking..

  8. I have an idea to get you started on porting this to OC. There are a few libraries that aren't available globally like their CC counterparts.

    I.E. the term library isn't global and yadda.... This is a step to get you on your way.

    -- Component lib for access to the gpu
    local component = require "component"
    
    -- Put term lib into local space..
    local term = require "term"
    
    -- Other libs we need as well
    local colors = require "colors"
    local textutils = require "serialization" -- CC to OC. The 'serialize' method is used the same here i think....
    local gpu = component.getPrimary('gpu')
    local fs = require "filesystem"
    
    -- 'term' Compatibility. These libs are similar in interface but OC lib has shorter method names. 
    term.setCursorPos, term.getCursorPos = term.setCursor, term.getCursor
    term.setTextColor, term.setBackgroundColor = gpu.setForeground, gpu.setBackground
    
    

    This should solve a decent portion of compatibility. Hope this helps.. Post back if you have questions..

  9. If you have autorun.lua enabled by default in OpenOs, which I believe it is by default, the easiest way is create a new file in / dir named 'autorun.lua' and save this text...

    <CODE>

    os.execute("resolution Xwidth Yheight")

    xwidth and height are strings of the number width and height you want

    <\CODE>

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.