[Windows Mobile Themes] j101399j:
Edit and update: I'm going through line by line, and taking them out, So far I have taken out the create reg line at the start, and my phone still resets?!?!?! So far I know this is not the error

if (regkey < 1)
RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 1)
EndIf

Well I don't know what went wrong. It follows through perfectly, it even created the reg entry and set it to "1". However within 1-2 seconds after running the script the phone resets, and keeps reseting everytime the code runs. Can you guys looks at the code and see if you can find why it resets the phone; maybe becasue of the new reg line? I'm going to test it without creating a new reg line and see if it still flips out

#batterylevelindicator by chancer63 with major changes by j101399j

#get IPT ready to reset if needed
RegWriteDword ("HKLM","Software\iPhoneToday","reloadIcons",0)
sleep ( 2000 )

#remove script from notification queue to make sure that you have only 1 script running
RemoveNotifications( "\iPhoneToday\battery\mybatterylevel.mscr" )
RemoveNotifications( "\iPhoneToday\battery\thebattlevel.mscr" )
RemoveNotifications( "\iPhoneToday\battery.mscr" )
RemoveNotifications( "\iPhoneToday\mybatterylevel.mscr" )

#Test and create reg file if needed????
regkey = Regread("HKLM","Software\iPhoneToday\battery","dummy")

if (regkey < 1)
RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 1)
EndIf

#set "last" to reg value
last = Regread("HKLM","Software\iPhoneToday\battery","dummy")

#compare battery % and set "current" key value

If (BatteryPercentage () > 94 )
current = 11
Elseif (BatteryPercentage () > 84 )
current = 10
Elseif (BatteryPercentage () > 74 )
current = 9
Elseif (BatteryPercentage () > 64 )
current = 8
Elseif (BatteryPercentage () > 54 )
current = 7
Elseif (BatteryPercentage () > 44 )
current = 6
Elseif (BatteryPercentage () > 34 )
current = 5
Elseif (BatteryPercentage () > 24 )
current = 4
Elseif (BatteryPercentage () > 14 )
current = 3
Elseif (BatteryPercentage () > 8)
current = 2
Else
current = 1
Endif

#Test if charging and set current
If (ExternalPowered () = 1)
current = 12
EndIf

#find out if day or night and set reset time
GetTime ( hour, min, sec)
now = TimeStamp()
If (hour > 6 and hour < 21)
nexttime = now + (15 * 60)
Else
nexttime = now + (90 * 60)
EndIf

#Resets the reset trigger to 0; if stays 0 iPT will reset
reset = 0

# check for charging and read the battery level and find out the fitting icon
#Test if same icon and end if true, other wise test for charging and end if true, or change icon and end

If (last = 12)
reset = 2
#End script and run again in 60 seconds
ElseIf (last = current)
reset = 1
#Reset at normal time and don't reset iPT
ElseIf (curent = 12)
Copy( "\iPhoneToday\battery\icons\charging.png", "\iPhoneToday\battery\battery.png", TRUE )
RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 12)
reset = 2
ElseIf (current = 11 )
Copy( "\iPhoneToday\battery\icons\100.png", "\iPhoneToday\battery\battery.png", TRUE )
RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 11)
Elseif (current = 10 )
Copy( "\iPhoneToday\battery\icons\90.png", "\iPhoneToday\battery\battery.png", TRUE )
RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 10)
Elseif (current = 9 )
Copy( "\iPhoneToday\battery\icons\80.png", "\iPhoneToday\battery\battery.png", TRUE )
RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 9)
Elseif (current = 8 )
Copy( "\iPhoneToday\battery\icons\70.png", "\iPhoneToday\battery\battery.png", TRUE )
RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 8)
Elseif (current = 7 )
Copy( "\iPhoneToday\battery\icons\60.png", "\iPhoneToday\battery\battery.png", TRUE )
RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 7)
Elseif (current = 6 )
Copy( "\iPhoneToday\battery\icons\50.png", "\iPhoneToday\battery\battery.png", TRUE )
RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 6)
Elseif (current = 5 )
Copy( "\iPhoneToday\battery\icons\40.png", "\iPhoneToday\battery\battery.png", TRUE )
RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 5)
Elseif (current = 4 )
Copy( "\iPhoneToday\battery\icons\30.png", "\iPhoneToday\battery\battery.png", TRUE )
RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 4)
Elseif (current = 3 )
Copy( "\iPhoneToday\battery\icons\20.png", "\iPhoneToday\battery\battery.png", TRUE )
RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 3)
Elseif (current = 2)
Copy( "\iPhoneToday\battery\icons\10.png", "\iPhoneToday\battery\battery.png", TRUE )
RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 2)
Else
Copy( "\iPhoneToday\battery\icons\00.png", "\iPhoneToday\battery\battery.png", TRUE )
RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 1)
Endif

#iPT Reset test
if (reset = 1)
RunAt( nexttime, "\iPhoneToday\battery\thebattlevel.mscr" )
#run script at normal time and do not reset iPT
ElseIf (reset = 2)
RunAt( now + 60, "\iPhoneToday\battery\thebattlevel.mscr" )
#run script in60 seconds and do not reset iPT
Else
RegWriteDword ("HKLM","Software\iPhoneToday","reloadIcons",1)
RunAt( nexttime, "\iPhoneToday\battery\thebattlevel.mscr" )
#run script at normal time and reset iPT
Endif

#Fixed code to run on power on 8-13 05:57
#
#
#to be up- to- date when switching the phone on
RunOnPowerOn ("\iPhoneToday\battery\thebattlevel.mscr")

Basically the code goes

1. gets iPT ready to reset

2. Removes notifactions

3. Checkes for regestery, if not present, it creates a new reg entry

4. sets "last" to the stored reg value

5. sets "current" to a key value beased on battery %

6. If charging sets "current" to 12 (12 is the value for charging)

7. Sets reset times

8. Sets "reset" key value (0 reset normal, 1 reset normal and no reset iPT, 2 reset 60 sec)

9. Tests, if last = 12, reset script at 60 seconds, no reset iPT

---------if last = current, reset script normal, no reset iPT

---------if current = 12 reset at 60 seconds, reset iPT

---------else, test and set reg value to current and reset script normal, reset iPT

10. run reset time based on "reset" vlue

11. run on wake