This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
madscientist712's profile picture

How do i fix the 'unexpected symbol' error

Started by madscientist712, 23 February 2015 - 05:41 PM
madscientist712 #1
Posted 23 February 2015 - 06:41 PM
I have a code for a big reactor to show me info about it but I want it so if a certain amount of energy is stored it will turn off the reactor. However On my code I have this line

local r = reactor1.getEnergyStored()
then if r < than 9000000 
 reactor1.setAllControlRodLevels(100)

The '<' symbol is what i think is the error but that is supposed to represent 'greater than' so I need that. Is it something else or the wrong symbol?
Cranium #2
Posted 23 February 2015 - 08:55 PM
local r = reactor1.getEnergyStored()
if r > 9000000 then
	reactor1.setAllControlRodLevels(100)
end

If/then statements follow this structure:

if condition then
    action
elseif otherCondition then
    otherAction
else
    finalAction
end
Edited on 23 February 2015 - 07:56 PM
Bomb Bloke #3
Posted 23 February 2015 - 09:18 PM
< is "less than", > is "greater than". "< than" is "less than than".
TheOddByte #4
Posted 23 February 2015 - 09:39 PM
Haven't they ever taught you in math class that '>' is greater than, and '<' is lesser than? :P/>
I also want to point you to the PIL, where you can learn more about Lua.


And you forgot to close the code tag

[.code] code here [./code] ( remove the dots )
Edited on 23 February 2015 - 08:39 PM
deeredman1991 #5
Posted 24 February 2015 - 12:52 AM

local r = reactor1.getEnergyStored()

if r < 9000000 then --[[As many others have mentioned this is the "less than" symbol
if you want "greater than" you need the ">" symbol however this logic makes sense if you want to
trigger the control rods going to 100 if the energy stored in the reactor drops below 9000000]]

reactor1.setAllControlRodLevels(100)
end --not sure if you want this end here depends on the rest of your code.

try this. :)/> I believe the problem was the syntax of your if statement.
Edited on 23 February 2015 - 11:58 PM
madscientist712 #6
Posted 24 February 2015 - 03:41 PM
Thanks I want it so if it is over 9000000 it will put the rods to 100 so this helps. However I was always told < was greater than and > was less. Thanks anyway :)/>