Jump to content




[fixed]Bios 14: [String "EU"]:11 - unexpected symbol


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

#1 plazter

  • Members
  • 134 posts

Posted 23 March 2016 - 12:31 AM

Hey Pros!
so.. i got 8 MFSU's that i would like to get the total amount stored of.. but i keep getting this error..

Pastebin: chTCBcJA

Raw code:
Spoiler
Hope you can help!
//Plazter

Edited by plazter, 23 March 2016 - 05:26 PM.


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 23 March 2016 - 12:54 AM

It's complaining because you're adding without returning the value or assigning it to a variable.

Based on usage, you want all() to return the all of the stored EU added together.

local function all()
  return one.getEUStored() +

  two.getEUStored() +

  thr.getEUStored() +

  fou.getEUStored() +

  fiv.getEUStored() +

  six.getEUStored() +

  sev.getEUStored() +

  eig.getEUStored()
end

The formatting is a bit weird, but it is perfectly valid.

How I'd do it

Edited by KingofGamesYami, 23 March 2016 - 01:00 AM.


#3 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 23 March 2016 - 12:55 AM

The problem is in your all function. You aren't returning the value so it can be captured by your st variable. Try this...
local function all()
  return one.getEUStored() + two.getEUStored() + thr.getEUStored() + fou.getEUStored() + fiv.getEUStored() + six.getEUStored() + sev.getEUStored() + eig.getEUStored()
end

I don't have a way to test atm, but the above *should* work.

EDIT: :ph34r: 'd

Edited by Dog, 23 March 2016 - 12:56 AM.


#4 plazter

  • Members
  • 134 posts

Posted 23 March 2016 - 02:15 AM

View PostKingofGamesYami, on 23 March 2016 - 12:54 AM, said:

It's complaining because you're adding without returning the value or assigning it to a variable.

Based on usage, you want all() to return the all of the stored EU added together.

local function all()
  return one.getEUStored() +

  two.getEUStored() +

  thr.getEUStored() +

  fou.getEUStored() +

  fiv.getEUStored() +

  six.getEUStored() +

  sev.getEUStored() +

  eig.getEUStored()
end

The formatting is a bit weird, but it is perfectly valid.

How I'd do it

didnt think of doing that wrap trick, nice one :P, i forgot most of those tables and things :P just returned to CC :D
Thank for the reply!

View PostDog, on 23 March 2016 - 12:55 AM, said:

The problem is in your all function. You aren't returning the value so it can be captured by your st variable. Try this...
local function all()
  return one.getEUStored() + two.getEUStored() + thr.getEUStored() + fou.getEUStored() + fiv.getEUStored() + six.getEUStored() + sev.getEUStored() + eig.getEUStored()
end

I don't have a way to test atm, but the above *should* work.

EDIT: :ph34r: 'd

Be my guest!

#5 plazter

  • Members
  • 134 posts

Posted 23 March 2016 - 02:22 AM

for i, v in ipairs ( tMFSU) do
   local amount = 0
   amount = amount + v.getEUStored()
end
return amount
end

where and what is that V from?

#6 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 23 March 2016 - 02:41 AM

A for loop with ipairs (and pairs) loops through a table and returns two things, index and value. I in this case is index, v is value. If you can't figure it out, the index is the position of the element in the array, with string indexes being returned as the actual string, and the value being returned as whatever data type it is. In the case of tMFSU it's the wrapped peripheral at the index i.

for index, value in ipairs( tMFSU) do
  print(value)
  print(tMFSU[index])
end
Those will print out the exact same things.


Edit: I tried to edit my starting lowercase a to A, and somehow put F. What?

Edited by Dragon53535, 23 March 2016 - 02:56 AM.


#7 plazter

  • Members
  • 134 posts

Posted 23 March 2016 - 02:51 AM

View PostDragon53535, on 23 March 2016 - 02:41 AM, said:

F for loop with ipairs (and pairs) loops through a table and returns two things, index and value. I in this case is index, v is value. If you can't figure it out, the index is the position of the element in the array, with string indexes being returned as the actual string, and the value being returned as whatever data type it is. In the case of tMFSU it's the wrapped peripheral at the index i.

for index, value in ipairs( tMFSU) do
  print(value)
  print(tMFSU[index])
end
Those will print out the exact same things.
oh thanks!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users