View difference between Paste ID: YDEnJ78z and FvnQD0Ez
SHOW: | | - or go back to the newest paste.
1
------------------------------------------------------------
2
-- Name: RCMaster
3-
-- version: 1.1.2
3+
-- version: 1.1.3
4
-- Author: Dustin Rosebery
5
-- Description: Program that provides touchscreen turtle 
6
--				operation including movement, inventory,
7
--				placing, and mining.
8
-- setup: 4x4 advanced monitors with an advanced computer
9
--			on the bottom of the monitors with a wireless
10
--			modem on the right side. Also requires an
11
--			advanced turtle with RCreceive installed
12
--			and a wireless modem on the left side.
13
------------------------------------------------------------
14
15
m = peripheral.wrap("top")
16
modem = peripheral.wrap("right")
17
m.clear()
18
buttons = {}
19
20
-------------------------------------------------- 
21
-- button creation
22
--------------------------------------------------
23
24
-- Directional button background color
25
dirColor = colors.red
26
-- Inventory button background color 
27
invColor = colors.white
28
-- Inventory button text color
29
invTextColor = colors.black
30
---------------------------------
31
--Directional buttons
32
---------------------------------
33
34
-- fbut (forward)
35
fxMin = 23
36
fxSize = 7
37
fxMax = fxMin + fxSize - 1
38
39
fyMin = 6
40
fySize = 4
41
fyMax = fyMin + fySize - 1 
42
43
fbut = window.create(m,fxMin,fyMin,fxSize,fySize)
44
fbut.setBackgroundColor(dirColor)
45
fbut.restoreCursor()
46
fbut.redraw()
47
fbut.setCursorPos(1,2)
48
fbut.write("forward")
49
50
-- bbut (backwards)
51
bxMin = 23
52
bxSize = 7
53
bxMax = bxMin + bxSize - 1
54
55
byMin = 12
56
bySize = 4
57
byMax = byMin + bySize - 1
58
59
bbut = window.create(m,bxMin,byMin,bxSize,bySize)
60
bbut.setBackgroundColor(dirColor)
61
bbut.redraw()
62
bbut.restoreCursor()
63
bbut.setCursorPos(1,2)
64
bbut.write(" back  ")
65
bbut.redraw()
66
67
-- lbut (left)
68
lxMin = 19
69
lxSize = 7
70
lxMax = lxMin + lxSize - 1
71
72
lyMin = 9
73
lySize = 4
74
lyMax = lyMin + lySize - 1
75
76
lbut = window.create(m,lxMin,lyMin,lxSize,lySize)
77
lbut.setBackgroundColor(dirColor)
78
lbut.redraw()
79
lbut.setCursorPos(1,2)
80
lbut.write(" left  ")
81
82
-- rbut (right)
83
rxMin = 27
84
rxSize = 7
85
rxMax = rxMin + rxSize - 1
86
87
ryMin = 9
88
rySize = 4
89
ryMax = ryMin + rySize - 1
90
91
rbut = window.create(m,rxMin,ryMin,rxSize,rySize)
92
rbut.setBackgroundColor(dirColor)
93
rbut.redraw()
94
rbut.setCursorPos(1,2)
95
rbut.write(" right ")
96
97
-- ubut (up)
98
uxMin = 36
99
uxSize = 2
100
uxMax = uxMin + uxSize - 1
101
102
uyMin = 7
103
uySize = 3
104
uyMax = uyMin + uySize - 1
105
106
ubut = window.create(m,uxMin,uyMin,uxSize,uySize)
107
ubut.setBackgroundColor(dirColor)
108
ubut.restoreCursor()
109
for i = 1, uySize do
110
  ubut.setCursorPos(1,i)
111
  ubut.write("  ")
112
end
113
m.setCursorPos(36,6)
114
m.write("up")
115
116
-- dbut (down)
117
dxMin = 36
118
dxSize = 2
119
dxMax = dxMin + dxSize - 1
120
121
dyMin = 11
122
dySize = 3
123
dyMax = dyMin + dySize - 1
124
125
dbut = window.create(m,dxMin,dyMin,dxSize,dySize)
126
dbut.setBackgroundColor(dirColor)
127
dbut.restoreCursor()
128
for i = 1, dySize do
129
  dbut.setCursorPos(1,i)
130
  dbut.write("  ")
131
end
132
m.setCursorPos(35,14)
133
m.write("down")
134
135
----------------------------
136
--Inventory Buttons
137
----------------------------
138
139
invButtons = {}
140
141
ixMin = 1
142
ixSize = 14
143
ixMax = ixMin + ixSize - 1
144
iySize = 1
145
146
-- i0
147
i0yMin = 1
148
i0 = window.create(m,ixMin,i0yMin,ixSize,iySize)
149
i0.setTextColor(colors.white)
150
i0.restoreCursor()
151
i0.write("Inventory:")
152
table.insert(invButtons, i0)
153
154
-- i1
155
i1yMin = 2
156
i1 = window.create(m,ixMin,i1yMin,ixSize,iySize)
157
i1.setBackgroundColor(invColor)
158
i1.setTextColor(invTextColor)
159
i1.restoreCursor()
160
i1.write("              ")
161
table.insert(invButtons, i1)
162
163
-- i2
164
i2yMin = 3
165
i2 = window.create(m,ixMin,i2yMin,ixSize,iySize)
166
i2.setBackgroundColor(invColor)
167
i2.setTextColor(invTextColor)
168
i2.restoreCursor()
169
i2.write("              ")
170
table.insert(invButtons, i2)
171
172
-- i3
173
i3yMin = 4
174
i3 = window.create(m,ixMin,i3yMin,ixSize,iySize)
175
i3.setBackgroundColor(invColor)
176
i3.setTextColor(invTextColor)
177
i3.restoreCursor()
178
i3.write("              ")
179
table.insert(invButtons, i3)
180
181
-- i4
182
i4yMin = 5
183
i4 = window.create(m,ixMin,i4yMin,ixSize,iySize)
184
i4.setBackgroundColor(invColor)
185
i4.setTextColor(invTextColor)
186
i4.restoreCursor()
187
i4.write("              ")
188
table.insert(invButtons, i4)
189
190
-- i5
191
i5yMin = 6
192
i5 = window.create(m,ixMin,i5yMin,ixSize,iySize)
193
i5.setBackgroundColor(invColor)
194
i5.setTextColor(invTextColor)
195
i5.restoreCursor()
196
i5.write("              ")
197
table.insert(invButtons, i5)
198
199
-- i6
200
i6yMin = 7
201
i6 = window.create(m,ixMin,i6yMin,ixSize,iySize)
202
i6.setBackgroundColor(invColor)
203
i6.setTextColor(invTextColor)
204
i6.restoreCursor()
205
i6.write("              ")
206
table.insert(invButtons, i6)
207
208
-- i7
209
i7yMin = 8
210
i7 = window.create(m,ixMin,i7yMin,ixSize,iySize)
211
i7.setBackgroundColor(invColor)
212
i7.setTextColor(invTextColor)
213
i7.restoreCursor()
214
i7.write("              ")
215
table.insert(invButtons, i7)
216
217
-- i8
218
i8yMin = 9
219
i8 = window.create(m,ixMin,i8yMin,ixSize,iySize)
220
i8.setBackgroundColor(invColor)
221
i8.setTextColor(invTextColor)
222
i8.restoreCursor()
223
i8.write("              ")
224
table.insert(invButtons, i8)
225
226
-- i9
227
i9yMin = 10
228
i9 = window.create(m,ixMin,i9yMin,ixSize,iySize)
229
i9.setBackgroundColor(invColor)
230
i9.setTextColor(invTextColor)
231
i9.restoreCursor()
232
i9.write("              ")
233
table.insert(invButtons, i9)
234
235
-- i10
236
i10yMin = 11
237
i10 = window.create(m,ixMin,i10yMin,ixSize,iySize)
238
i10.setBackgroundColor(invColor)
239
i10.setTextColor(invTextColor)
240
i10.restoreCursor()
241
i10.write("              ")
242
table.insert(invButtons, i10)
243
244
-- i11
245
i11yMin = 12
246
i11 = window.create(m,ixMin,i11yMin,ixSize,iySize)
247
i11.setBackgroundColor(invColor)
248
i11.setTextColor(invTextColor)
249
i11.restoreCursor()
250
i11.write("              ")
251
table.insert(invButtons, i11)
252
253
-- i12
254
i12yMin = 13
255
i12 = window.create(m,ixMin,i12yMin,ixSize,iySize)
256
i12.setBackgroundColor(invColor)
257
i12.setTextColor(invTextColor)
258
i12.restoreCursor()
259
i12.write("              ")
260
table.insert(invButtons, i12)
261
262
-- i13
263
i13yMin = 14
264
i13 = window.create(m,ixMin,i13yMin,ixSize,iySize)
265
i13.setBackgroundColor(invColor)
266
i13.setTextColor(invTextColor)
267
i13.restoreCursor()
268
i13.write("              ")
269
table.insert(invButtons, i13)
270
271
-- i14
272
i14yMin = 15
273
i14 = window.create(m,ixMin,i14yMin,ixSize,iySize)
274
i14.setBackgroundColor(invColor)
275
i14.setTextColor(invTextColor)
276
i14.restoreCursor()
277
i14.write("              ")
278
table.insert(invButtons, i14)
279
280
-- i15
281
i15yMin = 16
282
i15 = window.create(m,ixMin,i15yMin,ixSize,iySize)
283
i15.setBackgroundColor(invColor)
284
i15.setTextColor(invTextColor)
285
i15.restoreCursor()
286
i15.write("              ")
287
table.insert(invButtons, i15)
288
289
-- i16
290
i16yMin = 17
291
i16 = window.create(m,ixMin,i16yMin,ixSize,iySize)
292
i16.setBackgroundColor(invColor)
293
i16.setTextColor(invTextColor)
294
i16.restoreCursor()
295
i16.write("              ")
296
table.insert(invButtons, i16)
297
298
299
-- cleans item names by removing modID:
300
function split(name)
301-
  write(name .. "\n")
301+
  start, stop = string.find( name, ":" )
302-
  start, stop  = string.find( name, ":" )
302+
303-
  write(start .. " " .. stop .. "\n")
303+
304
end
305
306
307
-- initial inventory button display
308
function initInventory()
309-
-- initial inventory button check
309+
310
    rednet.broadcast(i)
311
    senderID, message, protocol = rednet.receive()
312
    if message == "empty" then
313-
    senderID, message, protocol =rednet.receive()
313+
314-
    if message then
314+
315
    else
316
      output = split(message)
317
	  invButtons[i].setCursorPos(1,1)
318
      invButtons[i].write(output)
319
    else
320
      
321
    end
322
  end
323
end
324
325
326-
-- input listener
326+
-- updates inventory on inventory button click
327
function updateInventory(index)
328
  senderID, message, protocol = rednet.receive()
329
  invButtons[index].clear()
330
  invButtons[index].redraw()
331
  invButtons[index].restoreCursor()
332
  invButtons[index].setCursorPos(1,1)
333
  if not message == "empty" then
334
    output = split(message)
335
  else
336
	output = ("<empty>")
337
  end
338
  invButtons[index].write(output)
339
end
340
341
342
----------------------------------------------------------------------
343
-- Input listener
344
----------------------------------------------------------------------
345
while(true) do 
346
347
  rednet.open("right")
348
  initInventory()
349
350
  event, side, xpos, ypos = os.pullEvent("monitor_touch")
351
  write(xpos .. ", " .. ypos.."\n") -- show touch location
352
  
353
-- directional control
354
  if (     xpos >= fxMin and xpos <= fxMax and
355
           ypos >= fyMin and ypos <= fyMax )then
356
    rednet.broadcast("forward")
357
358-
	  rednet.broadcast(1)
358+
359-
	  senderID, message, protocol = rednet.receive()
359+
360-
	  i1.setCursorPos(1,1)
360+
361-
   write(message)
361+
362-
	  output = split(message)
362+
363-
	  i1.write(output)
363+
364
    rednet.broadcast("left")
365-
	  rednet.broadcast(2)
365+
366
  elseif ( xpos >= rxMin and xpos <= rxMax and
367-
	  rednet.broadcast(3)
367+
368
    rednet.broadcast("right")
369-
	  rednet.broadcast(4)
369+
370
  elseif ( xpos >= uxMin and xpos <= uxMax and
371-
	  rednet.broadcast(5)
371+
372
    rednet.broadcast("up")
373-
	  rednet.broadcast(6)
373+
374
  elseif ( xpos >= dxMin and xpos <= dxMax and
375-
	  rednet.broadcast(7)
375+
376
    rednet.broadcast("down")
377-
	  rednet.broadcast(8)
377+
378
-- inventory control
379-
	  rednet.broadcast(9)
379+
380
381-
	  rednet.broadcast(10)
381+
382
	  rednet.broadcast(ypos)
383-
	  rednet.broadcast(11)
383+
	  updateInventory(ypos)
384
385-
	  rednet.broadcast(12)
385+
386
      rednet.broadcast(ypos)
387-
	  rednet.broadcast(13)
387+
	  updateInventory(ypos)
388
389-
	  rednet.broadcast(14)
389+
390
	  rednet.broadcast(ypos)
391-
	  rednet.broadcast(15)
391+
	  updateInventory(ypos)
392
393-
	  rednet.broadcast(16)
393+
394
	  rednet.broadcast(ypos)
395
	  updateInventory(ypos)
396
397
	elseif( ypos == i5yMin ) then
398
	  rednet.broadcast(ypos)
399
	  updateInventory(ypos)
400
401
	elseif( ypos == i6yMin ) then
402
	  rednet.broadcast(ypos)
403
	  updateInventory(ypos)
404
405
	elseif( ypos == i7yMin ) then
406
	  rednet.broadcast(ypos)
407
	  updateInventory(ypos)
408
409
	elseif( ypos == i8yMin ) then
410
	  rednet.broadcast(ypos)
411
	  updateInventory(ypos)
412
413
	elseif( ypos == i9yMin ) then
414
	  rednet.broadcast(ypos)
415
	  updateInventory(ypos)
416
417
	elseif( ypos == i10yMin ) then
418
	  rednet.broadcast(ypos)
419
	  updateInventory(ypos)
420
421
	elseif( ypos == i11yMin ) then
422
	  rednet.broadcast(ypos)
423
	  updateInventory(ypos)
424
425
	elseif( ypos == i12yMin ) then
426
	  rednet.broadcast(ypos)
427
	  updateInventory(ypos)
428
429
	elseif( ypos == i13yMin ) then
430
	  rednet.broadcast(ypos)
431
	  updateInventory(ypos)
432
433
	elseif( ypos == i14yMin ) then
434
	  rednet.broadcast(ypos)
435
	  updateInventory(ypos)
436
437
	elseif( ypos == i15yMin ) then
438
	  rednet.broadcast(ypos)
439
	  updateInventory(ypos)
440
441
	elseif( ypos == i16yMin ) then
442
	  rednet.broadcast(ypos)
443
	  updateInventory(ypos)
444
445
	end
446
  end
447
end