Help with better code design


#1

In the game I track th date and time, which affects different stats and events. I have figured out a way to make this work, but as I work on this the code has grown rather large to say the least. With a ton of gosub and to many checks to mention. I am far from done with it, but thought someone smarter then myself may be able to come up with something that would be less demanding on the Game.

Here is my aim.
The date is set 03/12/13 to start the game. I have it broke down into the following variables. Day, month, year, day_count, and month_name.

So for each click of a choice will add an hour to the clock, 24 hours in a day. There are 12 months and each month has a set amount of days. Every 4 years 10 days are added in a 13th month.

So if any thoughts on this would be great. If not will make it work one way or the other. :slight_smile:


#2

Could you paste (or link to) the routines?


#3

@CJW I am still working on setting them up. So the code is very incomplete. I will post what I have, but on my phone so won’t be able to post until Sunday sometime. I was just looking to see if someone had already designed something like this or thoughts on keeping the code much smaller and less complex.


#4

lol spoke to soon, seems there was a hot spot here I could use with the laptop.
So the following code ties into the rest check and the date, time, and moth mod. This far from complete with random thoughts put down as well. But should give you a feel for the direction I am going in.


*comment check for rested
*label subg_1
*comment This is a check to made each time they rest.
*if (rested=100)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=99)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=98)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=97)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=96)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=95)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=94)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=93)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=92)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=91)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=90)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=89)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=88)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=87)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=86)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=85)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=84)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=83)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=82)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=81)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=80)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=79)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=78)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=77)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=76)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=75)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=74)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=73)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=72)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=71)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=70)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=69)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=68)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=67)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=66)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=65)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=64)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=63)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=62)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=61)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=60)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=59)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=58)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=57)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=56)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=55)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=54)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=53)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=52)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=51)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=50)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=49)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=48)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=47)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=46)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=45)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=44)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=43)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=42)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=41)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=40)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=39)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=38)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=37)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=36)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=35)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=34)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=33)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=32)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=31)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=30)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=29)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=28)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=27)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=26)
 *set rested 20
 *set restful "You are well rested"
 *return

code is to long so will have to break it up


#5

*elseif (rested=25)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=24)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=23)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=22)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=21)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=20)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested=19)
 *set restful "You are well rested"
 *return
*elseif (rested=18)
 *set rested 20
 *set restful "You feel refreshed and ready for the day"
 *return
*elseif (rested=17)
 *set rested 20
 *set restful "You feel refreshed and ready for the day"
 *return
*elseif (rested=16)
 *set restful ""
 *return
*elseif (rested=15)
 *set restful ""
 *return
*elseif (rested=14)
 *set restful ""
 *return
*elseif (rested=13)
 *set restful ""
 *return
*elseif (rested=12)
 *set restful ""
 *return
*elseif (rested=11)
 *set restful ""
 *return
*elseif (rested=10)
 *set restful ""
 *return
*elseif (rested=9)
 *set restful ""
 *return
*elseif (rested=8)
 *set restful "Still got some energy but will need to rest soon"
 *return
*elseif (rested=7)
 *set restful "Still got some energy but will need to rest soon"
 *return
*elseif (rested=6)
 *set restful "You know now would be a good time to take a nap"
 *return
*elseif (rested=5)
 *set restful "You know now would be a good time to take a nap"
 *return
*elseif (rested=4)
 *set restful "My butt is dragging in the dirt, need rest"
 *return
*elseif (rested=3)
 *set restful "My butt is dragging in the dirt, need rest"
 *return
*elseif (rested=2)
 *set restful "This has been a hell of a long day, need rest"
 *return
*elseif (rested=1)
 *set restful "This has been a hell of a long day, need rest"
 *return
*elseif (rested=0)
 *set restful "You are in danger of harming yourself without rest"
 *return
*else (rested<0)
 *set restful "You are starting to feel the affects of not resting, HT will drop until you rest."
 *return

*comment If it is clear to sleep it will continue on 
*label subg_2
*if sleep_clear
 *gosub subg_3 
*else
 Sorry it is not safe to sleep here
 *return

*Comment Need to tie this into the clock as well as the random encounter table for sleeping. Also need to do a check for danger to see if they can sleep.
*comment This is for when they choose to sleep and how long
*label subg_3
*if (sleep="20")
 Going to sleep the day away are we? Be as it may twenty hours it is.
 *gosub subg_4
 
*comment This is a check to see if they encounter anything durning their sleep.
*label sub_4
*if (sleep="20")
 *set sleep_encounter 20
 *gosub subg_5
 
*comment Date system starts at 3/12/3012 
*comment need to create month and day checker, this will modify the year
*comment day check, need to find calander I created from before, once it reaches the end rest to 1 then add 1 to month.
*Comment add calander to lapstone
*comment month check to modifiy the year and reset to the next month
*comment Time is tracked by each click of choice
*comment Clicking the lapstone will not affect the time
*comment For each click of choice will be 1 hour, have 24 hrs in a day. Max sleep time is 20 hours. 

*label subg_time
*if (clock=25)
 *set clock 0
 *set day +1
 *gosub subg_month_check
 *return
*else (clock=,24)
 *return

 *comment need to creat a month check based on the number will change the name of the month. Also add in pic.
*comment need to find the calander for the name and the days, so using month? in place of names for now.
*label subg_month_check
*if (month_name="month1")
 *goto subg_month1
 *return
*elseif (month_name="month2")
 *goto subg_month2
 *return
*elseif (month_name="month3")
 *goto subg_month3
 *return
*elseif (month_name="month4")
 *goto subg_month4
 *return
*elseif (month_name="month5")
 *goto subg_month5
 *return
*elseif (month_name="month6")
 *goto subg_month6
 *return
*elseif (month_name="month7")
 *goto subg_month7
 *return
*elseif (month_name="month8")
 *goto subg_month8
 *return
*elseif (month_name="month9")
 *goto subg_month9
 *return
*elseif (month_name="month10")
 *goto subg_month9
 *return
*elseif (month_name="month11")
 *goto subg_month11
 *return
*elseif (month_name="month12")
 *goto subg_month12
 *return

*comment below will start the month settings.
*label subg_month1
*set day_count 0
*gosub subg_day
*return

*label subg_month2
*set day_count 0
*gosub subg_day
*return
 
*label subg_month3
*set day_count 0
*gosub subg_day
*return

*label subg_month4
*set day_count 0
*gosub subg_day
*return

*label subg_month5
*set day_count 0
*gosub subg_day
*return

*label subg_month6
*set day_count 0
*gosub subg_day
*return

*label subg_month7
*set day_count 0
*gosub subg_day
*return

*label subg_month8
*set day_count 0
*gosub subg_day
*return

*label subg_month9
*set day_count 0
*gosub subg_day
*return

*label subg_month10
*set day_count 0
*gosub subg_day
*return

*label subg_month11
*set day_count 0
*gosub subg_day
*return

*label subg_month12
*set day_count 0
*gosub subg_day
*return

*label subg_day



#6

That does, look somewhat… Painful? I’ll take a look a closer look when I get home (couple of hours). If you could bullet point exactly what you need to be able to do, that’d help a lot.


#7

@CJW thanks. I have five stops going into Chicago today on Friday. Its going to be a long day. But once I shut down tonightI will post it.


#8

@lordirishdas: uuugghhhh, that looks needlessly painful. The good news is you’re right, there is a far better way. You can replace your first page and then some, with:


*comment check for rested
*label subg_1
*comment This is a check to made each time they rest.
*if (rested>16)
 *set rested 20
 *set restful "You are well rested"
 *return
*elseif (rested>9)
 *set restful ""
 *return
...

The > and < symbols are your friends. They can be used to handle a range of values in a single statement. For example, if (rested>16 ) handles rested = {100, 99, 98, … 18, 17}, while elseif (rested>9) handles rested = {16, 15, …, 11, 10}.

In addition, labels subg_month1 through subg_month12 seem to be entirely redundant, at least currently, since they all do the same thing. Keep them all only if you’re planning to have each of them do something different. Otherwise combine the ones that do the same thing, and that should cut down on the number gosubs.

There may be other efficiency issues, but those are the things that jump out at me during a very quick perusal.


#9

@P_Tigras makes some good points.
It would be considerably easier to do this if you kept months constant though - or use some mathematical pattern to produce the days - something to keep in mind perhaps?

I’ll hold further analysis until you can bullet point your requirements, just to make sure I don’t miss anything.


#10

@P_Tigras this makes sense to my wee pee brain. :slight_smile:

@CJW thank you as always, but from the both of you it think I have a much simpler approach now. Of course if I code my self into a corner I will holler.


#11

*if ((rested >= 81) and (rested <= 100))

   *set restful "You are well rested"

*if ((rested >= 61) and (rested <= 80))

   *set restful "You dont need sleep, your a pimp"

*if ((rested >= 41) and (rested <= 60))

   *set restful "Your a bit tired but sleep is for suckers"

*if ((rested >= 21) and (rested <= 40))

   *set restful "Okay, Your eyelids are heavy... but you can keep going"

*if ((rested >= 1) and (rested <= 20))

   *set restful "Okay, It's been a long day for a pimp, need rest."

*if (rested = 0)

   *set restful "Your a borderline zombie at this point."

*if (rested < 0)

   *set restful "You crave brains for some odd reason..."

I did it for you Lord, though my example is confusing since it’s just the raving of a madman thrown in.


#12

Lol @2Ton is awesome thanks :slight_smile:


#13

I confess the day was much longer then I planned. Have a headache from heck. Just getting to eat now You all did give great feedback but I will post bullet points just in case there is further insight I might learn. It just won’t be tonight. Have 8 hour drive tomorrow, short day, to get back to the house will post Sunday thanks all.,


#14

@lordirishdas You can do it, your pimp.


#15

@2Ton lol I don’t feel so pimp tonight.

*edit I am the anti-pimp tonight.


#16

@lordirishdas Well the pimp game isn’t an easy one my friend, sometimes your on a high, sometimes on a low, but remember the golden rule a pimp once told me… “Patience you must have my young padawan”


#17

@2Ton I bow to your wisdom. Peace out I heading to see the sandman about a dog, then hang with my Muse in Z land.


#18

@lordirishdas Oh, the sandman? he and I go way back! when you see him will you tell him I said Hi? and ask did his wife recover from that sand boarding accident?


#19

I did not put up bullet points yet as I still mapping out what I want. For now can any one point me in the direction of how to use ref affectivly. I read CoG document and Wiki but still at a loss to understand it. I have seen @CJW with and example of it and if I can wrap my pee brain around it may reduce the code by a lot. Thanks


#20

Can’t think of another way to do this… I’ll stretch my brain…