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

kind of function but not a function

Started by wilcomega, 07 August 2012 - 01:41 PM
wilcomega #1
Posted 07 August 2012 - 03:41 PM
look, i dont really get this logic stuff:

printCentred( math.floor(h/2) + 0, ((nDifficulty == 1) and "[  EASY  ]") or "EASY" )

ok i have 2 questions :P/>/>
1. how does this work
2. how to write this stuff

thx in advance
wilcomega
Noodle #2
Posted 07 August 2012 - 05:39 PM
Well for starters, where is the actual printCentered function?
It makes more sense if you could tell us or something…
Cranium #3
Posted 07 August 2012 - 05:52 PM
If you are talking about how the math works, then look here: Math Library
If you are trying to learn how to make interactive menus, I suggest you look here: A Quick Guide Through Menu Making
MysticT #4
Posted 07 August 2012 - 08:14 PM

printCentred( math.floor(h/2) + 0, ((nDifficulty == 1) and "[  EASY  ]") or "EASY" )
printCentred(): function call.
math.floor(h / 2) + 0: divide h by 2, floor the result and add 0.
Now the "hard" part:
((nDifficulty == 1) and "[ EASY ]") or "EASY"
This is like using an if statement. If nDifficulty equals 1, then return "[ EASY "], else return "EASY".
Pharap #5
Posted 08 August 2012 - 04:29 AM
Printcentred isn't a built in function. I take it you copied this code from someone else's project and want to use it to your own devices but know next to nothing about programming?