Overview
Thebackground.ahk script runs as a separate process alongside the main macro, continuously monitoring the Roblox window for critical game events and states.
Location: submacros/background.ahk
Purpose:
- Death detection
- Guiding Star buff detection
- Pop Star buff monitoring
- Night/day cycle detection
- Backpack percentage tracking
- Emergency balloon handling
- Daily reconnect scheduling
Initialization
The background script is launched by the main macro during startup:Requirements
The script must be launched with command-line arguments from the main macro. Manual execution will show an error.Arguments:
[1]NightLastDetected (unused)[2]VBLastKilled (unused)[3]StingerCheck[4]StingerDailyBonusCheck (unused)[5]AnnounceGuidingStar[6]ReconnectInterval[7]ReconnectHour[8]ReconnectMin[9]EmergencyBalloonPingCheck[10]ConvertBalloon[11]NightMemoryMatchCheck[12]LastNightMemoryMatch (unused)
State Management
Global State Variables
Current macro activity state:
0- Idle/traveling1- Gathering in field- Other values for specific activities
Overall macro status:
0- Stopped1- Paused2- Running
Unix timestamp of last reset/respawn. Used to prevent false death detection immediately after respawn.
OnMessage Handlers
The background script receives commands from the main macro:Message Handlers
Updates numeric variables from main script.Parameters:
wParam- Variable index in arraylParam- New value
- Index 1:
resetTime - Index 4:
StingerCheck - Index 6:
LastConvertBalloon - Index 7:
NightMemoryMatchCheck
Updates the current state from main script.Parameters:
wParam- New state valuelParam- Last state value
Main Loop
The background script runs an infinite loop with 1-second intervals:Detection Functions
Death Detection
Detects when the player dies by searching for the death screen image.Behavior:
- Checks bottom-right quadrant of screen
- Requires 20+ seconds since last reset
- Requires 10+ seconds since last death detection
- Uses
ImageSearchwith 50 variation tolerance - Sends
PostMessage 0x5555, 1, 1to main script - Sends “You Died” via
WM_COPYDATA
nm_image_assets/died.pngGuiding Star Detection
Detects when Guiding Star buff is active in fields.Behavior:
- Searches top portion of screen (offsetY+30 to offsetY+90)
- Only triggers when
state = 1(gathering) - Uses confirmation system (5 checks) before declaring buff ended
- Sends
PostMessage 0x5555, 6, 1when detected - Sends
PostMessage 0x5555, 6, 0when ended - Sends “Detected: Guiding Star Active” message
nm_image_assets/boostguidingstar.png
Tolerance: 50 variationPop Star Detection
Monitors Pop Star amulet stacks and active state.Behavior:
- Checks bottom 1/4 of screen
- Detects pop star counter to determine if buff is available
- Tracks two states:
HasPopStar(has stacks) andPopStarActive(buff active) - When counter visible: has stacks but not active
- When counter disappears during gathering: buff is active
- Sends state updates to main macro and StatMonitor
PostMessage 0x5555, 7, 1- Has pop star stacksPostMessage 0x5555, 8, 1- Pop star activePostMessage 0x5555, 8, 0- Pop star ended
nm_image_assets/popstar_counter.png
Tolerance: 30 variationNight Detection
Detects the night/day cycle for stinger spawns and night memory match.Behavior:
- Only runs if
StingerCheckorNightMemoryMatchCheckenabled - Scans bottom half of screen for lighting conditions
- Uses confidence system (6 consecutive detections)
- Distinguishes between day (0), night (1), and dusk (2)
- Maintains detection for 5 minutes after initial trigger
- Loads bitmaps from
nm_image_assets/night/andnm_image_assets/offset/
0- Day (nightConfidence <= 1)1- Night (nightConfidence >= 6 or within 5min of last detection)2- Dusk/transition (nightConfidence > 1 but < 6)
PostMessage 0x5552, 368, nightto main macroPostMessage 0x5552, 367, nightto PlanterTimers- Sends “Detected: Night” via WM_COPYDATA
Backpack Percentage Detection
Calculates backpack fill percentage using pixel color analysis.Behavior:
- Samples pixel at
windowX+windowWidth//2+59+3, windowY+offsetY+6 - Analyzes RGB color channels to determine fill level
- Returns percentage in 5% increments (0, 5, 10, … 95, 100)
- Bar is 220 pixels wide = 11 pixels per 5%
- Red channel increases as backpack fills
- Green/Blue channels decrease as backpack fills
- Uses bitwise AND with masks (0xFF0000, 0x00FFFF)
- Specific color thresholds for each 5% increment
Applies rolling average filter to backpack percentage for stability.Behavior:
- Maintains 6-sample rolling window (6 seconds @ 1Hz)
- Calculates rounded average of samples
- Updates StatMonitor every 6 seconds
- Sends updates to main macro when value changes
PostMessage 0x5555, 4, BackpackPercent(raw value)PostMessage 0x5555, 5, BackpackPercentFiltered(filtered value)PostMessage 0x5557, BackpackPercentFiltered, timestamp(to StatMonitor)
Guiding Star Field Detection
Detects which field has a Guiding Star and announces it.Behavior:
- Only runs if
AnnounceGuidingStar = 1 - Rate limited to once per 10 seconds
- Searches center-to-bottom-right area of screen
- Checks two different guiding star icon variations
- Searches each of 17 fields for field name image
- Sends notification to main macro when found
nm_image_assets/guiding_star_icon1.pngnm_image_assets/guiding_star_icon2.png- Field images in
nm_image_assets/fields/
Daily Reconnect
Triggers scheduled reconnect at specified time.Behavior:
- Checks if current time matches
ReconnectHour:ReconnectMin - Only triggers once per minute window
- Sends
PostMessage 0x5555, 3, 1to main macro - Resets after 60 seconds to prevent multiple triggers
Emergency Balloon
Forces balloon conversion based on time since last convert.Behavior:
- Only runs if
EmergencyBalloonPingCheck = 1 - Activates if
ConvertBalloon = "Every"orConvertBalloon = "Never" - Checks if 2+ hours since last balloon conversion
- Sends emergency balloon notification
- Updates
LastConvertBalloontimestamp
Bitmap Loading
The background script loads detection bitmaps during initialization:Case-insensitive map storing GDI+ bitmap pointers for image detection.Categories:
offset- UI offset detection bitmapsnight- Night/day detection bitmaps- Other detection images loaded as needed
Communication Protocol
Sending to Main Macro
Event Types (0x5555)
Values:
1- Death detected3- Daily reconnect time reached4- Backpack percent (raw)5- Backpack percent (filtered)6- Guiding Star state (lParam: 1=active, 0=inactive)7- Has Pop Star stacks8- Pop Star active state
Window Management
The background script uses Roblox window detection functions from the library:Coordinate System
Cleanup
See Also
- Main Script Reference - Main macro control and initialization
- Library Functions Reference - Roblox.ahk detection functions