Clock and Calendar function using variables

EDIT: I started working on the calendar function. Check out my latest post.

I was working on a snippet script, but I haven't got this working yet.

I'm trying to reduce the number of conditional branches for this one. I want this script to show the message after calculating the variables.

I'll request the calendar after changing the thread to 'Clock and Calendar function using variables'.

Here are the variables:
$game_variables[1: Time of Day]
$game_variables[4: 1 Hour]

And these later on:
$game_variables[2: 1 min]
$game_variables[3: 10 min]
$game_variables[23: meridiem]

meridiem is for AM/PM.

Here's a conditional branch example:
Spoiler: Conditional Branch
Conditional Branch: $game_variables[1] >= 60 && $game_variables[1] <= 119 || $game_variables[1] >= 780 && $game_variables[1] <= 839

Control Variables[4] = 1

Branch End
Conditional Branch: $game_variables[1] >= 120 && $game_variables[1] <= 179 || $game_variables[1] >= 840 && $game_variables[1] <= 899

Control Variables[4] = 2

Branch End
Conditional Branch: $game_variables[1] >= 180 && $game_variables[1] <= 239 || $game_variables[1] >= 900 && $game_variables[1] <= 959

Control Variables[4] = 3

Branch End
Conditional Branch: $game_variables[1] >= 240 && $game_variables[1] <= 299 || $game_variables[1] >= 960 && $game_variables[1] <= 1019

Control Variables[4] = 4

Branch End
Conditional Branch: $game_variables[1] >= 300 && $game_variables[1] <= 359 || $game_variables[1] >= 1020 && $game_variables[1] <= 1079

Control Variables[4] = 5

Branch End
Conditional Branch: $game_variables[1] >= 360 && $game_variables[1] <= 419 || $game_variables[1] >= 1080 && $game_variables[1] <= 1139

Control Variables[4] = 6

Branch End
Conditional Branch: $game_variables[1] >= 420 && $game_variables[1] <= 479 || $game_variables[1] >= 1140 && $game_variables[1] <= 1199

Control Variables[4] = 7

Branch End
Conditional Branch: $game_variables[1] >= 480 && $game_variables[1] <= 539 || $game_variables[1] >= 1200 && $game_variables[1] <= 1259

Control Variables[4] = 8

Branch End
Conditional Branch: $game_variables[1] >= 540 && $game_variables[1] <= 599 || $game_variables[1] >= 1260 && $game_variables[1] <= 1319

Control Variables[4] = 9

Branch End
Conditional Branch: $game_variables[1] >= 600 && $game_variables[1] <= 659 || $game_variables[1] >= 1320 && $game_variables[1] <= 1379

Control Variables[4] = 10

Branch End
Conditional Branch: $game_variables[1] >= 660 && $game_variables[1] <= 719 || $game_variables[1] >= 1320 && $game_variables[1] <= 1379

Control Variables[4] = 11

Branch End
Conditional Branch: $game_variables[1] >= 720 && $game_variables[1] <= 779 || $game_variables[1] == 1380 || $game_variables[1] <= 59

Control Variables[4] = 12

Branch End

The 'time of day' variable was used as minutes.

Here's a script I've come up with:
Ruby:
def clock_call(id)
#  one_hour  = $game_variables[4]
#  one_min   = $game_variables[2]
#  ten_min   = $game_variables[3]
  meridiem = $game_variables[23]
  total_min = $game_variables[1]

  hour = $game_variables[4]
  ten = $game_variables[3]
  one = $game_variables[2]
 
  return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].any? { |hour| } && [1, 2, 3, 4, 5, 6].any? { |ten| } && [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].any? { |one| }
  return $game_message.add("Time: |hour|")
end

This script is WIP.
I'm not really sorry for telling you this but you messed up with the local and block variables.
Any variable defined inside |pipes| becomes a block variable. You should avoid that. Plus, in this case they are useless because you simply defined them for no good reason.
Why are you trying to do there? Finding a single number?
If that's the case replacing any? {|ten|} with include?(ten) simplifies the process and will return a valid, useful boolean value.
I fixed a problem. Thanks! But there's another problem. I tried to show a message with a script.

Here are the examples. One of them could be correct:
Ruby:
def clock_call(id)
#  one_hour  = $game_variables[4]
#  one_min   = $game_variables[2]
#  ten_min   = $game_variables[3]
  meridiem  = $game_variables[23]
  total_min = $game_variables[1]

  hour = $game_variables[4]
  ten = $game_variables[3]
  one = $game_variables[2]
 
  return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].include?(hour) && [1, 2, 3, 4, 5, 6].include?(ten) && [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].include?(one)
  return $game_message.add("Time: |hour|:|ten||one|")
end

Ruby:
def clock_call(id)
#  one_hour  = $game_variables[4]
#  one_min   = $game_variables[2]
#  ten_min   = $game_variables[3]
  meridiem  = $game_variables[23]
  total_min = $game_variables[1]

  hour = $game_variables[4]
  ten = $game_variables[3]
  one = $game_variables[2]
 
  return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].include?(hour) && [1, 2, 3, 4, 5, 6].include?(ten) && [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].include?(one)
  return $game_message.add("Time: (hour):(ten)(one)")
end

They could be neither too. Maybe the show message function was for script call, not the script itself.
where is the parameter (id) used in the script?
return $game_message.add("Time: (hour)🙁ten)(one)")
return $game_message.add("Time: #{hour}:#{ten}#{one}")
return $game_message.add("Time: #{hour}:#{ten}#{one}")
This does not open the message at all, thank you for trying. Try click the code to the right side of a crossed out eyeball that's called; spoiler.
It's okay, when I first post a script, I haven't use a code.

Here's a script code:
Ruby:
  return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].include?(hour) && [0, 1, 2, 3, 4, 5].include?(ten) && [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].include?(one)
  return $game_message.add("Time: #{hour}:#{ten}#{one}")

The point is I should use a show text function for the snippet script. Think of this as Show Text for the conversation, only telling the time.

Edit: This code does work. Turns out return was the problem.
Forgive me for spamming. I figured it out.

Here's a script:
Ruby:
def clock_call(id)
#  one_hour  = $game_variables[4]
#  one_min   = $game_variables[2]
#  ten_min   = $game_variables[3]
  meridiem  = $game_variables[23]
  total_min = $game_variables[1]

  hour = $game_variables[4]
  ten = $game_variables[3]
  one = $game_variables[2]
 
  return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].include?(hour) && [0, 1, 2, 3, 4, 5].include?(ten) && [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].include?(one) && $game_message.add("Time: #{hour}:#{ten}#{one}")
end

Instead of return, I replace it with && instead.

Edit: I planned to shorten the return code and variables with this script:
Spoiler: Snippet script
Ruby:
def clock_call(id)
  medim  = $game_variables[5]
  min = $game_variables[1]

  hour = $game_variables[4]
  ten = $game_variables[3]
  one = $game_variables[2]
 
  return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].include?(hour)

  return [0, 1, 2, 3, 4, 5].include?(ten)

  return [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].include?(one)
 
  if min == 0 || min == 10 || min == 20 || min == 30 || min == 40 || min == 50 || min == 60
    one == 0
  end
 
  if min == 1 || min == 11 || min == 21
    one == 1
  end
 
  if min == 10 || min == 70 || min == 130 || min == 190 || min == 260 || min == 320
    one == 1
  end
 
  if min >= 720 && min <= 779 || min >= 1440 || min <= 59
    hour == 12
  end
 
  if min >= 1440
    min -= 1440
  end
 
  if min >= 60 && min <= 119 || min >= 780 && min <= 839
    hour == 1
  end
 
  if min >= 120 && min <= 179 || min >= 840 && min <= 899
    hour == 2
  end

  if min >= 180 && min <= 239 || min >= 900 && min <= 959
    hour == 3
  end
 
  if min >= 240 && min <= 299 || min >= 960 && min <= 1019
    hour == 4
  end
 
  if min >= 300 && min <= 359 || min >= 1020 && min <= 1079
    hour == 5
  end
 
  if min >= 360 && min <= 419 || min >= 1080 && min <= 1139
    hour == 6
  end
 
  if min >= 420 && min <= 479 || min >= 1140 && min <= 1199
    hour == 7
  end
 
  if min >= 480 && min <= 539 || min >= 1200 && min <= 1259
    hour == 8
  end
 
  if min >= 540 && min <= 599 || min >= 1260 && min <= 1319
    hour == 9
  end
 
  if min >= 600 && min <= 659 || min >= 1320 && min <= 1379
    hour == 10
  end
 
  if min >= 660 && min <= 719 || min >= 1380 && min <= 1439
    hour == 11
  end

  if [0..719, 1440].include?(min)
    medim == "AM"
  else if [720..1439].include?(min)
    medim == "PM"
  end
end

  return $game_message.add("Time: #{hour}:#{ten}#{one} #{medim}")
end
I tried next, then and when but nothing worked. Adding end to the return might cause an error.
I started working on a calendar script to go with a clock script.

For some reason, I get errors popping up for trying to shorten out the variables. Ex. $game_variables[1].

Here are two snippets.

Calendar:
Ruby:
def calendar_call(id)
 
  m = $game_variables[1]
  one = $game_variables[2]
  ten = $game_variables[3]
  hour = $game_variables[4]
  medim  = $game_variables[5]
  day = $game_variables[6]
  mon = $game_variables[7]
  year = $game_variables[8]
  t_day = $game_variables[17]
  w_name = $game_variables[18]
  m_name = $game_variables[19]
  week = $game_variables[20]
  leap_y = $game_variables[21]

  return $game_message.add("Calendar: #{mon}/#{day}/#{year}\nWeek: #{$game_variables[18]}\nMonth: #{$game_variables[19]}")
end

Clock and Time Pass:
Add Spoiler to save room. You may open this.
Spoiler: Clock Script
Ruby:
def time_pass(id)
 
  m = $game_variables[1]
  one = $game_variables[2]
  ten = $game_variables[3]
  hour = $game_variables[4]
  medim  = $game_variables[5]
  day = $game_variables[6]
  mon = $game_variables[7]
  year = $game_variables[8]
  t_day = $game_variables[17]
  w_name = $game_variables[18]
  m_name = $game_variables[19]
  week = $game_variables[20]
  leap_y = $game_variables[21]
 
  if m >= 1
    one += 1
    m -= 1
  end

  if $game_variables[2] >= 10
    $game_variables[3] += 1
    $game_variables[2] -= 10
  end
 
  if $game_variables[4] >= 11 && $game_variables[5] == "AM" && $game_variables[3] >= 6
    $game_variables[5] == "PM"
    $game_variables[4] += 1
    $game_variables[3] -= 6
  end
 
  if $game_variables[4] >= 11 && $game_variables[5] == "PM" && $game_variables[3] >= 6
    $game_variables[5] == "AM"
    $game_variables[6] += 1
    $game_variables[4] += 1
    $game_variables[3] -= 6
  end
 
  if $game_variables[3] >= 6
    $game_variables[4] += 1
    $game_variables[3] -= 6
  end
 
  if $game_variables[4] >= 13
    $game_variables[4] -= 12
  end
 
  if $game_variables[20] >= 8
    $game_variables[20] -= 7
  end
 
  if total_day == d
    mon += 1
    d = 1
  end
 
  if mon >= 13
    y += 1
    l += 1
    mon -= 12
  end
 
  if l >= 5
    l -= 4
  end
 
  if $game_variables[7] == 1 || $game_variables[7] == 3 || $game_variables[7] == 4 || $game_variables[7] == 7 || $game_variables[7] == 8 || $game_variables[7] == 10 || $game_variables[7] == 12
    $game_variables[17] = 31
  end
 
  if $game_variables[7] == 2 && $game_variables[21] <=3
    $game_variables[17] = 28
  else if $game_variables[7] == 2 && $game_variables[21] == 4
    $game_variables[17] = 29
  end
end

  if $game_variables[7] == 5 || $game_variables[7] == 6 || $game_variables[7] == 9 || $game_variables[7] == 11
    $game_variables[17] = 30
  end
 
  if $game_variables[20] == 1
    $game_variables[18] = "Sunday"
  end
 
  if $game_variables[20] == 2
    $game_variables[18] = "Monday"
  end
 
  if $game_variables[20] == 3
    $game_variables[18] = "Tuesday"
  end
 
  if $game_variables[20] == 4
    $game_variables[18] = "Wednesday"
  end
 
  if $game_variables[20] == 5
    $game_variables[18] = "Thursday"
  end
    
  if $game_variables[20] == 6
    $game_variables[18] = "Friday"
  end
 
  if $game_variables[20] == 7
    $game_variables[18] = "Saturday"
  end
 
  if $game_variables[7] == 1
    $game_variables[19] = "January"
  end
 
  if $game_variables[7] == 2
    $game_variables[19] = "February"
  end
 
  if $game_variables[7] == 3
    $game_variables[19] = "March"
  end
 
  if $game_variables[7] == 4
    $game_variables[19] = "April"
  end
 
  if $game_variables[7] == 5
    $game_variables[19] = "May"
  end
    
  if $game_variables[7] == 6
    $game_variables[19] = "June"
  end
 
  if $game_variables[7] == 7
    $game_variables[19] = "July"
  end
 
  if $game_variables[7] == 8
    $game_variables[19] = "August"
  end
 
  if $game_variables[7] == 9
    $game_variables[19] = "September"
  end
 
  if $game_variables[7] == 10
    $game_variables[19] = "October"
  end
 
  if $game_variables[7] == 11
    $game_variables[19] = "November"
  end
 
  if $game_variables[7] == 12
    $game_variables[19] = "December"
  end
 
def clock_call(id)

  return [$game_message.add("Time: #{$game_variables[4]}:#{$game_variables[3]}#{$game_variables[2]} #{$game_variables[5]}")]
  end
end

The calendar script is above the time pass script.

Remember adding the code to ruby. No pressure.

Original thread: https://forums.rpgmakerweb.com/threads/clock-and-calendar-function-using-variables.167303/