Jump to content




Counting order of inputs (array?)



  • You cannot reply to this topic
5 replies to this topic

#1 Ashton

  • Members
  • 44 posts

Posted 02 May 2013 - 11:11 PM

ok, I'm working on an "infinite maze" it's a crossroads of all four directions (N/S/E/W) with pressure plates at the end that teleports the player to the opposite end and records the "exit", so in theory, I could track the player's "exits" and make as complex of a maze as I want, or change it as often as I want.

I want to track 4 inputs (most recent last four) And, for example, if they are N, N, W, N, then that triggers a teleportation, while N, N, N, S does not.

I've set up my program to count the inputs, and if any input exceeds 4 it teleports the player back to the start and resets the counter.

I am using the rs.getInput() command to determine which "direction" the player moved, and I can fill the four slots (if var1 = null, var1 = rs.input, if var1 != null, than (var2, var3, var4) ---- not actual code, obviously) but what do I do once all four inputs are full? How to I tell it to begin recycling? I can recycle #1 by saying "if var4 =! null, then (var1) but after that, if I start over the code will begin to conflict because it will look for a "null" slot and there wont be one...

So, basically, how do I set it up to continually update the "last 4 inputs"?

current (severely incomplete) code (wrapping command block as a peripheral on bottom):
local N = 0
local S = 0
local E = 0
local W = 0
local cblock = peripheral.wrap("bottom")
local redo = cblock.setCommand("/tp @p 263 63 -149") cblock.runCommand() N=0 S=0 E=0 W=0 sleep(1)

--back is S,
--front is N,
--right is W,
--left is E

while true do

if rs.getInput("back") == "true" then S = S + 1 end
if rs.getInput("front") == "true" then N = N + 1 end
if rs.getInput("right") == "true" then W = W + 1 end
if rs.getInput("left") == "true" then E = E + 1 end

if S == 4 then redo() end
if N == 4 then redo() end
if E == 4 then redo() end
if W == 4 then redo() end

end

Current thoughts:

(note: warp1/etc would be a function to set and execute a command block /tp command)

local pos1 = null
local pos2 = null
local pos3 = null
local pos4 = null
local GetDir = null

if rs.getInput() == "back" then GetDir == "S" end
if rs.getInput() == "right" then GetDir == "W" end
if rs.getInput() == "left" then GetDir == "E" end
if rs.getInput() == "front" then GetDir == "N" end


if pos1 = null then pos1 = GetDir end


if pos2 = null then pos2 = GetDir end


if pos3 = null then pos3 = GetDir end


if pos4 = null then pos4 = GetDir end


if pos4 ~= null then pos1 = GetDir end

if (pos1=N) and (pos2=N) and (pos3=W) and (pos4=S) then Warp1() sleep(1) end

if (pos1=W) and (pos2=N) and (pos3=N) and (pos4=E) then Warp2() sleep(1) end

if (pos1=S) and (pos2=S) and (pos3=W) and (pos4=S) then Warp3() sleep(1) end


Thoughts on how to impliment this and where to go from here?

#2 Mackan90096

  • Signature Abuser
  • 518 posts
  • LocationIn my basement.

Posted 03 May 2013 - 04:39 AM

First of all.. Please put the code in code tags, as it will become easier for people to help you.

#3 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 03 May 2013 - 10:10 AM

You might want to declare "redo" as a function, not as the return value of cblock.setCommand...
local redo = function()
    cblock.setCommand("/tp @p 263 63 -149")
    cblock.runCommand()
    N=0
    S=0
    E=0
    W=0
    sleep(1)
end


#4 Ashton

  • Members
  • 44 posts

Posted 03 May 2013 - 08:16 PM

So... nobody has any clue how to make the 4 variables just loop? O_o

about the only thing I can do at this point is force the 5th teleport to always be a reset if the correct order is not obtained...

View PostMackan90096, on 03 May 2013 - 04:39 AM, said:

First of all.. Please put the code in code tags, as it will become easier for people to help you.

Sorry, used to people saying "spoiler anything long" I'll use the cod tags instead.

View PostLBPHacker, on 03 May 2013 - 10:10 AM, said:

You might want to declare "redo" as a function, not as the return value of cblock.setCommand...
local redo = function()
	cblock.setCommand("/tp @p 263 63 -149")
	cblock.runCommand()
	N=0
	S=0
	E=0
	W=0
	sleep(1)
end

Been a while since I programmed and that was a very different lanaguage. I'll do that.

#5 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 04 May 2013 - 01:51 AM

Threw this together in the early morning - hopefully it works, but if it doesn't, you still got a bunch of comments to learn from...
Spoiler


#6 Ashton

  • Members
  • 44 posts

Posted 04 May 2013 - 01:52 PM

Well... the code is good (except I'm getting an error about trying to index a nil value, but that's not important now) however, after running the gamut 10 times, I only got the correct response once. While the redstone/PC/CommandBlock is a great tool the redstone wiring and pressure-plates are just WAY too unreliable to use... if I were to export this as a single-player map it might work, but as it is, the redstone doesn't always transmit, is delayed, etc, so I either get no input or sometimes inputs out of order due to lag spikes... (I even tried placing buttons 2 blocks from the PC and using those for the redstone signals, still didn't get the right response unless I pressed, waited, watched and if the redstone didn't activate, hit it a second time...)

I'm severely dissapointed, this mod has SO MUCH potential to revolutionize dungeon building since it can allow the creation of macros/scripts that straight redstone doesn't allow... but the game itself is too unstable for it to work reliably... looks like I'm going to have to go back to building a physical maze... maybe if RedPower ever releases a new update I'll try the cables to see if they're more reliable than the redstone...

Thanks though! I really do appreciate it :)





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users