Ok, So I’ve been playin around with this for around a week or so, but I cannot, for the life of me, figure out how to extratc the month itself from the os.date function! Any help will be soo much help!
http://www.lua.org/pil/22.1.html
Full month name: os.date("B")
Abbreviated month name: os.date("b")
Month number: os.date("m")
@Codeanoob i frequently use google when looking for a lua function. Google:
lua os.date
gives as first link the one posted by jakattak, and all details of syntax.
So, I have this code:
function draw()
background(0,0,0,255)
local A = os.date('%B')
fill(255,255,255,255)
text(A,100,100)
if A == 'February' then
text('Winter',100,85)
end
end
Could anyone tell me why the ‘Winter’ text isnt showing, even though the month displayed IS February?
this is strange: for me it is showing ‘winter’ below ‘february’
Works for me too
Hmm, doesnt for me…
Works fine here.
Could it be my iPad mini?
[EDIT]: It works when I do it in a new, empty project. Weird
In the project I was testing, No variables were the same, and it didnt show, but when I put this code in a new, blank project, it works. I’m confused!
so you have a bigger project that includes this code and doesnt work? But it works with just this code?
=> you sure are making something wrong in the bigger project. Cant help you without the code.
It really wasnt that big, only around 20 lines more, and i have 0 dependencies, i’ll try again tho, persistence is key
I had a similar problem once, where a simple piece of code wasn’t working. The problem was a dependency; when I added the other project, they both had a function with the same name. Result was that my simple function call called the function in the dependent project, not my own. Just had to rename my function.
If you have any dependencies, ensure no other global variable A exists in them.
if it is so small why dont you post the code and sby points the bug out? i doubt it is persistance, 99% chance it is just a st*****d bug.
--# Button
Button = class()
function Button:init(x2,y2,w2,h2,c2,t,f)
-- you can accept and set parameters here
self.x2 = x2
self.y2 = y2
self.w2 = w2
self.h2 = h2
self.c2 = c2
self.t = t
self.f = false
end
function Button:draw()
pushMatrix()
pushStyle()
rectMode(CENTER)
fill(self.c2)
translate(self.x2,self.y2)
--ellipse(-self.w2/2,0,self.h2)
--ellipse(0+self.w2/2,0,self.h2)
rect(0,0,self.w2,self.h2)
fill(255, 255, 255, 255)
text(self.t,0,0)
popStyle()
popMatrix()
end
function Button:touched(t)
if t.state == ENDED and t.x < -self.w2/2 and t.y > -self.h2/2 and t.x < self.w2/2 and t.y < self.h2/2 then
Button:callBack()
end
end
function Button:callBack()
state = 'Play'
end
--# Main
Menu = 'Menu'
Play = 'Play'
Shop = 'Shop'
state = 'Menu'
function setup()
--CheckData()
dw = 100--readLocalData('dw')
if state == 'Menu' then
Paddle:init(color(0,0,0),WIDTH/2,15,dw,15)
Button:init(WIDTH/2,HEIGHT/2,100,50,color(0,0,0),'Play')
else
alert('Hi',Hi)
end
end
function draw()
backingMode(RETAINED)
local A = os.date('%B')
if A == 'February' then
text('Winter',100,100)
background(127, 127, 127, 255)
fill(255, 255, 255, 255)
text(A,100,100)
Paddle:draw()
Button:draw()
end
end
function touched(t)
Button:touched(t)
end
--# Paddle
Paddle = class()
function Paddle:init(c,x,y,w,h)
self.c = c
self.x = x
self.y = y
self.w = w
self.h = h
end
function Paddle:draw()
pushMatrix()
translate(self.x,self.y)
self.x = self.x + Gravity.x*20
pushStyle()
rectMode(CENTER)
fill(self.c)
rect(0,0,self.w,self.h)
if self.x + self.w/2 > WIDTH then
self.x = WIDTH - self.w/2
elseif
self.x - self.w/2 < 0 then
self.x = self.w/2
end
popStyle()
popMatrix()
end
@CodeaNoob - in the original code you showed us, the month and “Winter” were being drawn in different places. In the code above, you are drawing them in exactly the same place, so Winter is being overwritten by the other text.
os.date("*t")
gives you a ready to use table with all information.
there you go, the bug is fired thanks to Mr @Ignatz. There is no persistance of variable with codea between runs.