Jump to content
Sign in to follow this  
niubbone

Make a little self calendar system

Recommended Posts

niubbone

I'm making a small game in which I want to include a small calendar needed to check some events and that advances by one day every action I make.

The game is like a little life simulator, so, when you hang out with a girl, go out with friends, study and so on a day passes for each action.

Therefore I created a basic starting date stored in a variable as a string. Then, when needed, I created a function that should add a single day to the date everytime it's called.

But something seems not to work with _DateAdd

Here's the first chunk of code I came up with (thanks todanwilli):

#include <Date.au3>
Global $date = "2010/12/20"
Global $NewDate = $date
For $i = 1 To 5
    $NewDate = _DateAdd('d', 1, $NewDate)
    MsgBox(4096, "", "Today + 1 days:" & _Format($NewDate))
Next
Func _Format($FDate)
    Return StringRight($FDate,2) & '/' & StringMid($FDate,6,2) & '/' & StringLeft($FDate,4)
EndFunc
MsgBox(0,"new date check",$newdate)
;this for example wil add 5 days but in final function
;will be added only 1 day removing the for 1 to 5 cycle

This adds the date for 5 days consecutively and I can even bring the date value out of the loop for later use.

Now, Since the code of the game will be lot of lines, to make it smaller I would had liked to bring all the code in a function, so whenever I need i can call it and add 1 day to the current standalone game calendar date.

This is what I tried, but it doesn't works... Any suggestion?

#include <Date.au3>
Global $date = "2010/12/20"
Global $NewDate = $date
Global $case1=3
Global $case2=7
If $case1>2 Then
    DayAfter($NewDate)
    Msgbox(0,"try",$NewDate)
EndIf
If $case2>3 Then
    DayAfter($NewDate)
    Msgbox(0,"try",$NewDate)
EndIf
Func DayAfter($Data)
Local $NewDate = $Data
    $NewDate = _DateAdd('d', 1, $NewDate)
    MsgBox(4096, "", "Today + 1 days:" & StringRight($NewDate,2) & '/' & StringMid($NewDate,6,2) & '/' & StringLeft($NewDate,4))
EndFunc

I don't know how to make that the new modified date keep being added to the previous so I can make day 20, day 21, 22 ,23 and so on making the game run all the days, the months and the years from the date I set at the beginning....

Thanks for help

EDIT. I think I solved this.

Edited by niubbone

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.