Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

impose a curfew on a card

A topic by BenyDanette created 1 day ago Views: 76 Replies: 5
Viewing posts 1 to 2
(2 edits) (+1)

Hi everyone.

I would like to be able to allow or deny access to the content of the game I am creating based on the time of day.

More specifically, I want to impose a curfew that would prohibit going to a go to a card game between 8 a.m. and 10 p.m.

So far, this is how I've done it:  I created a field called “hour” with the following content:

"on change val do

end

on view do

p:“%p” parse “%e” format sys.now

b:(p.hour)

end"

Then a button that checks the content of this field:

"if

home.widgets.hour.text=21

dd.say[“ACCESS DENIED”]

dd.close[]

elseif

home.widgets.hour.text=22

dd.say[“ACCESS ALLOWED”]

dd.close[]

go[“card1” ‘Dissolve’]"

In this situation, only two hours are checked...

I would also like to be a little permissive, allowing the button to go to the next card as long as the seconds contain a “7.”
And finally, I would like to add an easter egg if players click on the button on a specific time (combination of hour and minute, for example 12:13) 

Could you tell me how to do this? I don't know how to code this in an elegant and logical way. Thanks :)

Developer(+1)

Parsing "sys.now" into time-parts like your example:

p:"%p" parse "%e" format sys.now

Gives us a dictionary like so:

{"year":2025,"month":12,"day":18,"hour":23,"minute":30,"second":45}

Note that this time is in GMT. The hour (and possibly minute) values might need to be adjusted to reflect a time zone offset to get local time. Otherwise, people in certain countries might find the game much harder than others!

At any rate, we'll want to structure our checks from most to least specific. First, the easter-egg time. We want both p.hour to be equal to 12 AND p.minute to be equal to 13:

(p.hour=12)&(p.minute=13)

Parentheses are important here: remember that arithmetic precedence in Lil is right-to-left unless otherwise grouped by parentheses or brackets.

Since seconds range between 0 and 59, 7 appears in the seconds place iff p.second modulo 10 is equal to 7:

(7=10%p.second)

For your hour ranges, you'll probably need ">" and "<"; there are many ways to express the same thing:

  (p.hour<10) | (p.hour>19)
! (p.hour >9) & (p.hour<20)
! p.hour in (10,11,12,13,14,15,16,17,18,19)

Bringing it all together, here's one possible approach for what you described:

if (p.hour=12)&(p.minute=13)
 # easter egg...
elseif (p.hour<10) | (p.hour>19) | (7=10%p.second)
 # allowed...
else
 # denied...
end

Does that make sense?

(5 edits)

It's weird, the "easter egg" and "second 7" restriction works perfectily, but the curfew between two specific hours doesn't... 
Here is the code I wrote with your indication :

__

p:"%p" parse "%e" format sys.now 
if (p.hour+1=12)&(p.minute=13)  
dd.say["EASTEREGG"]  
dd.close[]  
go["card1" "Dissolve"]  
elseif (7=10%p.second)  
dd.say["HACK#7SECONDS#DONTGETCAUGHT#"]  
dd.close[]  
go["card1" "Dissolve"]  
elseif (p.hour+1>10) & (p.hour+1<20)  
dd.say["###ACCES AUTORISE###COUVRE-FEU DE 10H A 20H###"]  
dd.close[]  
go["card1" "Dissolve"] 
 
else  
dd.say["###ACCES INTERDIT###COUVRE-FEU DE 10H A 20H###"]  
dd.close[]  
end

__

you can check the project here : https://benydanette.itch.io/amok (password : curfew)
(note : i set "p.hour+1" to have the right time in my country)

Developer(+1)

Like I said previously, remember that arithmetic precedence in Lil is right-to-left unless otherwise grouped by parentheses or brackets!

Without parentheses, Lil understands an expression like

p.hour+1>10

as equivalent to

p.hour+(1>10)

and not

(p.hour+1)>10

after 1 hour of attempt I can't figure out how to do it :/
The second works, the special easter egg also, but the curfew from an hour to another doesn't

sorry I feel stupid, but could you save me with a piece of code ? 

(1 edit) (+1)

I think the issue is just your parentheses () placement.  If we look at this line:

elseif (p.hour+1>10) & (p.hour+1<20)

You only need the parentheses to be around p.hour and your +1 adjustment to the time. Putting it in it's own set of parentheses makes sure that this part is done first before the script checks if the number is in the correct range . So you could change that line to be like this instead:

((p.hour+1) >10) & ((p.hour+1) <20)

Hopefully that makes sense?

Optionally, another way to do this would be to modify what p.hour is at the beginning of your script like this:

p:"%p" parse "%e" format sys.now 
utc_offset:1 
p.hour:24%utc_offset+p.hour

The first line is the same as what you have now.

The second line defines a new variable called utc_offset which I'm going to use to say how many hours off from utc your time zone is. (1)

And the third line sets p.hour to be p.hour plus your utc_offset. The 24% in this line keeps the result consistent with 24 hour time. So if the math it was doing for p.hour was 23+1 it would go back to 0 instead of up to 24.

If  this version makes sense to you then you could put this at the beginning of your script and just refer to p.hour for the rest of it without needing to modify it again, because it's already been modified.