Jump to content




Code throwing java exceptions after updating CC

lua java computer

3 replies to this topic

#1 DasTebbers

  • Members
  • 5 posts

Posted 11 May 2015 - 08:11 PM

What I have is secondhand code, since I, myself, am not versed in lua. It runs a slot machine that takes items as pay, pays out other items based on the stake and displays on a light grid. The original is https://youtu.be/kBnGO0wTDpk, as well as a quick scroll through the code.

Initially, I copied the build in mc1.6.4 with CC 1.58, converting to use rednet and buildcraft, and all was well. I've now recreated it in MC1.7.10 with CC 1.73, which has taken a switch in wiring to use Red Power's cables. I was able to rework the redstone aspects of the code to work, currently, it acknowledges that a coin is inserted, and pulls it out to find the stake, gets the signal identifying the stake, then nothing. The computer only gives the error "Java Exception Thrown: java.lang.IllegalArgumentException: number expected"

I've tried to diagnose where the error is by inserting print commands into the various functions, which have since been deleted to start fresh with the original code. From that, I can tell it's calling the fruitdrop function, but something in that must be throwing the error, since no print commands after that appear, but that's only a guess on my part.

Here's what I'm running currently:

grid = {
  {"red", "blue", "lightGray"},
  {"black", "brown", "green"},
  {"white", "cyan", "purple"}
}

function sndBum()
  rs.setBundledOutput("left", colors.white)
  sleep(0.1)
  rs.setBundledOutput("left", 0)
end

function sndTick()
  rs.setBundledOutput("left", colors.orange)
  sleep(0.1)
  rs.setBundledOutput("left", 0)
end

function sndDing()
  rs.setBundledOutput("left", colors.magenta)
  sleep(0.1)
  rs.setBundledOutput("left", 0)
end

function draw()
  local out = 0
  local i
  for i=1,3 do
	if gfx[i] >= 1 and gfx[i] <= 3 then
	 out = colors.combine(out, grid[i][gfx[i]])
   end
end
if win then
  out = colors.combine(out, colors.orange)
end
rs.setBundledOutput("top", out)
end

function resetGame()
  win = false
  gfx = {0,0,0}
  draw()
  sleep(1)
end

function fruitDrop(gfx, mov, ed, decr)
  local i
  for i=1,3 do
	if mov[i] then
	 gfx[i] = gfx[i] + 1

	if gfx[i] > 3 then
	 gfx[i] = 1
	end
  
   if gfx[i] == ed[i] and decr[i] < 0 then
	mov[i] = false
   end

   decr[i] = decr[i] - 1
   end
end
sndTick()
end

function r3(max)
  return {math.random(max),math.random(max),math.random(max)}
end

function playGame(stake)
  gfx = r3(3)
  local mov = {true, true, true}
  local ed = r3(3)
  local decr = r3(10)

  -- at least 1/4 plays will win
  if math.random() < 0.25 then
	local wl = math.random(3)
	ed = {wl,wl,wl}
  end

while true do
  fruitDrop(gfx, mov, ed, decr)

   if mov[1] == false and mov[2] == false and mov[3] == false then
	break
   end
  
   draw()
   sleep(0.5)
  end

  if gfx[1] == gfx[2] and gfx[2] == gfx[3] then
   win = true
   draw()
   if stake == 1 then
	payOut(10)
   elseif stake == 2 then
	payOut(1)
   end
   sleep(3)
  end

  draw()
end

function payOut(amt)
  for _=1,amt do
	rs.setBundledOutput("top", colors.gray)
	sleep(0.5)
	rs.setBundledOutput("top", 0)
	sleep(0.3)
	sndDing()
  end
end

function evCoinInserted()
  if rs.testBundledInput("top", colors.pink) then
	return 1
  elseif rs.testBundledInput("top", colors.lime) then
	return 2
  end
  return false
end

function jumpstart()
  rs.setBundledOutput("top", colors.yellow)
  sleep(0.2)
  rs.setBundledOutput("top",0)
end

function evJumpstart()
  if rs.testBundledInput("top", colors.lightBlue) then
	sleep(2)
	jumpstart()
  end
end

jumpstart()
while true do
  if os.pullEvent() == "redstone" then

  coin = evCoinInserted()
	if coin ~=false then
	 playGame(coin)
	 sleep(2)
	 if win == false then
	  sndBum()
   end
   resetGame()
   jumpstart()
  end
  evJumpstart()
  end
end



#2 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 11 May 2015 - 10:40 PM

View PostDasTebbers, on 11 May 2015 - 08:11 PM, said:

I've tried to diagnose where the error is by inserting print commands into the various functions, which have since been deleted to start fresh with the original code. From that, I can tell it's calling the fruitdrop function, but something in that must be throwing the error, since no print commands after that appear, but that's only a guess on my part.

I don't see any places in the 'fruitdrop' function that could cause that error.

Try putting 'print's for every line to see which line is the problem.

#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 11 May 2015 - 11:49 PM

out = colors.combine(out, grid[i][gfx[i]])

colours.combine() requires (at least) two numbers. Here you're passing a number followed by a string. Try switching to:

out = colors.combine(out, colors[grid[i][gfx[i]]])


#4 DasTebbers

  • Members
  • 5 posts

Posted 12 May 2015 - 12:55 AM

View PostBomb Bloke, on 11 May 2015 - 11:49 PM, said:

out = colors.combine(out, grid[i][gfx[i]])

colours.combine() requires (at least) two numbers. Here you're passing a number followed by a string. Try switching to:

out = colors.combine(out, colors[grid[i][gfx[i]]])

That sorted it! Is it a version differing thing that it worked before and not now?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users