Jump to content




[Lua] [string "shell"]:18: unexpected symbol


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

#1 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 17 December 2012 - 05:57 AM

Hello all! I have been editing the shell file for fun (using copy rom/programs/shell shell; edit shell) trying to get it to use a random color every time on an advanced computer. Recently i have come across this error:
[string "shell"]:15: unexpected symbol
when editing the file. Here is the code from lines 1-21. I only edited lines 15-17, but the rest is included just in case.

local parentShell = shell
local bExit = false
local sDir = (parentShell and parentShell.dir()) or ""
local sPath = (parentShell and parentShell.path()) or ".:/rom/programs"
local tAliases = (parentShell and parentShell.aliases()) or {}
local tProgramStack = {}
local shell = {}
local tEnv = {
["shell"] = shell,
}
-- Colours
local promptColour, textColour, bgColour
if term.isColour() then
promptColour = colours.2^math.random(0,15)   --Edited lines. Also lines with error. XD
textColour = colours.2^math.random(0,15)  --Edited lines. Also lines with error. XD
bgColour = colours.2^math.random(0,15)  --Edited lines. Also lines with error. XD
else
promptColour = colours.white
textColour = colours.white
bgColour = colours.black
end
Please help! :)

Btw, can an admin change title to: [Lua] Error when editing shell file

#2 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 17 December 2012 - 07:22 AM

So I'm guessing it's impossible? :(

#3 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 17 December 2012 - 09:55 AM

Remove the 'colours.' before the '2^math.random(0,15)' and it should work, and then to set colours:
term.setTextColour(promptColour)


#4 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 17 December 2012 - 10:18 AM

That works, but it doesn't switch colors every command.

#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 December 2012 - 10:49 AM

shell has its own functionality where it sets it to black. so if shell is running at same time it wont change it.

#6 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 17 December 2012 - 10:53 AM

What do you mean it doesn't switch colours every command?

#7 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 17 December 2012 - 11:10 AM

The text, once you input a command, does not change colors again until rebooted.

#8 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 17 December 2012 - 11:12 AM

]Screenshot:

[attachment=786:2012-12-16_15.12.33.png

Attached Thumbnails

  • Attached Image: 2012-12-16_15.12.33.png


#9 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 17 December 2012 - 11:14 AM

View PostTheOriginalBIT, on 17 December 2012 - 10:49 AM, said:

shell has its own functionality where it sets it to black. so if shell is running at same time it wont change it.

I am running an edited version of shell, editable by using: "copy rom/programs/shell; edit shell"

#10 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 17 December 2012 - 11:14 AM

View PostMudkipTheEpic, on 17 December 2012 - 11:10 AM, said:

The text, once you input a command, does not change colors again until rebooted.

Yeah thats because you only change it there and not anywhere else? It will need to be in other places too, like a loop. Show us your code and we can show you where to put it

Edit: Oh that's what you mean, hmm. Yeah well then I'm not entirely sure about that, because it only changes the colour once that program is run...

#11 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 17 December 2012 - 11:17 AM

Ok. But its a long one:

Spoiler

Well I got it to work before, but it shows an error on non-advanced computers.

#12 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 December 2012 - 11:20 AM

thats maybe bacause you cant call term.setBackgroundColor() or setTextColor() on a non-advanced computer. A similar error would occur in 1.3 computers too.

#13 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 17 December 2012 - 11:25 AM

View PostTheOriginalBIT, on 17 December 2012 - 11:20 AM, said:

thats maybe bacause you cant call term.setBackgroundColor() or setTextColor() on a non-advanced computer. A similar error would occur in 1.3 computers too.

Lol. You can, but only with black and white (text colours) and only black for background.

#14 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 17 December 2012 - 11:26 AM

That's exactly what I mean. I need it to disable the color functions if the computer is not advanced.

#15 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 December 2012 - 11:26 AM

View PostremiX, on 17 December 2012 - 11:25 AM, said:

View PostTheOriginalBIT, on 17 December 2012 - 11:20 AM, said:

thats maybe bacause you cant call term.setBackgroundColor() or setTextColor() on a non-advanced computer. A similar error would occur in 1.3 computers too.

Lol. You can, but only with black and white (text colours) and only black for background.

Last time I tried it it errored out.

#16 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 December 2012 - 11:27 AM

View PostMudkipTheEpic, on 17 December 2012 - 11:26 AM, said:

That's exactly what I mean. I need it to disable the color functions if the computer is not advanced.

each time you go to use colour functions you could do this

this will allow it to run on CC1.3 and above
if term.isColor and term.isColor() then
  -- do colour functions
else
  -- do non-colour functions
end


#17 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 17 December 2012 - 11:28 AM

And I'm not that much of a noobish coder, I just know virtually nothing about functions.

And I just released my first program! :D http://www.computerc...e-fake-console/

#18 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 17 December 2012 - 11:29 AM

Umm, the thing is, shell is so full of functions and variables my head would explode sifting through them. XD





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users