Jump to content




Function Call Error


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

#1 KDJSAIUH

  • Members
  • 35 posts

Posted 27 October 2013 - 05:48 PM

I wrote this program and when i go through it all (username=kai pass=nuke then enter rednet) it says 'defcon:188: attempt to call string'. I have looked at it and tried all i can and it wont work.

Code:

Spoiler

http://pastebin.com/ZjF6eYTL

pastebin get zjf6eytl defcon

Note: Sorry for long code.
This code is un-finished
Error is in rednetApi function where it says r()

#2 Bomb Bloke

    Hobbyist Coder

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

Posted 27 October 2013 - 06:12 PM

Although you define r as a function at line 119, as soon as you call rednetSide() it gets overwritten with a string.

#3 KDJSAIUH

  • Members
  • 35 posts

Posted 28 October 2013 - 05:10 AM

Thanks, but how do i fix this?

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 28 October 2013 - 05:35 AM

what you should be doing is making sure to use local variables and better naming conventions.

Local variables
local foo = "bar" --# this variable is only accessible by this program and anything defined BELOW this declaration

local function hello() --# this function is only usable by the program and anything defined BELOW this declaration
  local world = "world!" --# this variable is ONLY accessible by THIS FUNCTION
  print(world)
end

Coding conventions
Variable overriding can be avoided by reducing naming collisions... Instead of naming a function `r` perhaps it could be name `run` or `runProgram` or `resetData` or something of the such. Variable names are commonly suggested to be descriptive of what they contain, function names are normally suggested to start with a verb and describe what they do in ~15 characters or less, with the exception being a function that returns a boolean variable where it is prefixed with `is` or `are`, `isAlive` or `arePointsColliding`. Another common technique to avoid naming collisions in Lua is to prefix the variable with the first letter of its type, for example a boolean would be `bAlive`, a string `sName`, etc.

The best solution for you would be to rename your variables and functions to something a little more descriptive to avoid problems.

#5 KDJSAIUH

  • Members
  • 35 posts

Posted 28 October 2013 - 06:15 AM

Thanks I found it thanks to you to (eventualy) i realised my mistake. #suchANoob





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users