Esempio n. 1
0
        public object Connect(object[] args)
        {
            string name = ReturnValueConversions.SafeUnwrap <string>(args, 0);

            //Console.WriteLine(_caller + " connecting to " + name);
            MimanTing maybeTing = GetTingFromNameOrSourceCodeName(_tingRunner, name);

//			if (maybeTing is Character) {
//				_caller.Say("Can't connect to human " + name);
//				return new ReturnValue(-1);
//			} else
            if (maybeTing != null)
            {
                //_caller.PlaySound ("Modem");
                return(_caller.AddConnectionToTing(maybeTing));
            }
            else
            {
                if (_caller is Computer)
                {
                    (_caller as Computer).API_Print("Can't find " + name + " to connect to");
                }
                else
                {
                    _caller.Say("Can't find " + name + " to connect to", "");
                }
                return(-1f);
            }
        }
Esempio n. 2
0
        object API_print(object[] args)
        {
            string pretty = ReturnValueConversions.PrettyStringRepresenation(args[0]);

            output.Add(pretty);
            Console.WriteLine("output: " + pretty);
            return(VoidType.voidType);
        }
Esempio n. 3
0
        public object RemoteFunctionCall(object[] args)
        {
            float  receiverIndex = (int)ReturnValueConversions.SafeUnwrap <float>(args, 0);
            string functionName  = ReturnValueConversions.SafeUnwrap <string>(args, 1);

            if (args [2].GetType() != typeof(SortedDictionary <KeyWrapper, object>))
            {
                throw new Error("Argument array to " + functionName + " is not an array");
            }

            var argsAsReturnValues = ReturnValueConversions.SafeUnwrap <SortedDictionary <KeyWrapper, object> >(args, 2);

            if (_caller.connectedTings.Length == 0)
            {
                _caller.Say("No connected object to call function on", "");
                return(0f);
            }

            if (receiverIndex == -1)
            {
                _caller.Say("Connection not open, can't call function.", "");
                return(0f);
            }
            else if (receiverIndex < 0)
            {
                _caller.Say("Receiver index is below 0: " + receiverIndex, "");
                return(0f);
            }
            else if (receiverIndex >= _caller.connectedTings.Length)
            {
                _caller.Say("Receiver index is too big (" + _caller.connectedTings.Length + ")", "");
                return(0f);
            }

            MimanTing receiverTing = _caller.connectedTings[(int)receiverIndex];

            receiverTing.PrepareForBeingHacked();

            if (receiverTing.programs.Length == 0)
            {
                _caller.Say("Connected thing has no programs to call", "");
                return(0f);
            }

            var fixedArgs = argsAsReturnValues.Values.ToArray();

            receiverTing.masterProgram.StartAtFunctionIfItExists(functionName, fixedArgs, _program);
            _program.waitingForInput = true;

            return(0f);            // "WAITING FOR RETURN VALUE FROM REMOTE FUNCTION";
        }