• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Help with Pedometer / Step-Counter Script

65
Posts
8
Years
  • Hello,

    I need help to set up a Pedometer / Step-Counter Script that checks if a Player has done a certain amount of steps. If the Player has done those steps (let's say 600), he/she should be directed to a pointer where something happens. (For now I use 5 steps as a test)

    I've tried to search for something in the Safari Zone-Script, but I couldn't figure out what counts and checks for the 600 max. Steps ... Here I figured out that the var 0x4025 is used to count steps & I've also tried out the JPAN's Pedometer Flags, as I use CFRU. But unfortunatly, I still don't get my Level2-Scritpt to work :(

    Here's my script:

    #org @start
    msgbox @begin 0x6

    addvar 0x4087 0x1
    setvar 0x4087 0x1

    setvar 0x4025 0x5 / setvar 0x922 0x5
    compare LASTRESULT 0x5
    if 0x1 goto @timeEnd '-- If "x" Steps are reached goto @timeEnd
    release
    end

    #org @timeEnd
    msgbox @end 0x6
    fadescreen 0x1
    warpmuted 0x3 0x5 0xFF 0x7 0xB
    fadescreen 0x0
    return

    #org @begin
    = Ok let's start!
    return

    #org @end
    = Time's up ...
    return


    --------------------------------------------

    Thank you :)
     

    DrFuji

    [I]Heiki Hecchara‌‌[/I]
    1,691
    Posts
    14
    Years
  • The variable 0x4025 is only used for Daisy's massages in the post-game. It counts up to a max of 500 steps so while it works as a pedometer, its somewhat limited. Here's a type 2 level script that utilises the CFRU pedometer system that should do what you're looking for with some comments to explain what's going on:

    Code:
    #dynamic 0x800000
    
    #org @start
    msgbox @LetsStart 0x4
    loadpointer 0x0 @PedometerScript 
    special 0x81 // In conjunction with the above command, the script beginning at the @PedometerScript pointer will be run every step
    setflag 0x921 // Turns on a 16-bit pedometer that can count up to 0xFFFF (65535) steps
    setvar 0x4050 0x0 // Cleans the variable chosen to count how many steps are taken - Ensure nothing else can affect this variable while the walking script is active
    setvar 0x4051 0x1 // Variable to deactivate the level script so it doesn't get stuck in a endless loop
    release
    end
    
    #org @PedometerScript
    setvar 0x8004 0x2 // Tells the 0x8A special that we're reading the 16-bit pedometer
    special2 0x4050 0x8A // Stores the value of the 16-bit pedometer in variable 0x8005
    compare 0x4050 0x258 // Compares the value held in 0x4050 to 0x258 (600 steps)
    if 0x1 goto @MaxSteps // If the value is equal, you've made 0x258 steps and the script branches off
    releaseall
    end
    
    #org @MaxSteps // This portion of the script mainly deals with resetting the pedometer/ walking script
    msgbox @Finished 0x4
    writebytetooffset 0x0 0x203B7C4 // Resetting the pedometer in the RAM to 0
    writebytetooffset 0x0 0x203B7C5 // Resetting the pedometer in the RAM to 0
    clearflag 0x921 // Turns off the 16-bit pedometer
    loadpointer 0x0 0x0
    special 0x81 // Turns off the script that activates every step
    setvar 0x4051 0x0 // Resets the level script's variable so the next time the player step into a map with this level script it will activate and start everything all over again
    warp 0x3 0x5 0xFF 0x7 0xB // Warps to the chosen map
    
    #org @LetsStart
    = Ok, let's start!
    
    #org @Finished
    = Time's up[.]
     
    Last edited:
    65
    Posts
    8
    Years
  • Hi DrFuji,

    thank you so much for your help 😃 And for the detailled explanation too ^_^ I learned a lot from that. Especially that the special 0x81 is very powerful. If I understood this right, then this special executes & asks the Level2-Script everytime, so I guess to create a Timer that automatically ask itself it's value should be possible after all 😍

    I did tried out the script as a Level2-Script, but after I make 1 step, the Player is unable to move 🤔 I even used the same 4050 & 4051 Vars as you (though I could use other vars too, as long those Vars aren't used elsewhere, right?).

    I've also changed the #raw word to 0x0. I looked deeper down in the Map Offset-Code and noticed that the loadpointer has some weird characters (see Screenshot attached -There's also code from a Level3-Script from that same map, but both are completly different from one another). And the value for 4051 is set to 0 in A-Map

    Have you encounter such a problem too?

    I also checked for typos, but it doesn't seem as there are any (Sometimes XSE doesn't recognize copied code)

    Thank you
    Xero3C
     

    Attachments

    • Weird Message LoadPointer.PNG
      Weird Message LoadPointer.PNG
      44.8 KB · Views: 12
    Last edited:

    DrFuji

    [I]Heiki Hecchara‌‌[/I]
    1,691
    Posts
    14
    Years
  • The garbled part of the script is because the loadpointer command is only supposed to load text, rather than other scripting commands. XSE is trying to display all of the commands as a text string which obviously doesn't work out too well, but the data should still be okay in-game :P

    I'm not sure why you're unable to move after one step as the script worked fine on my ROM. The only thing that I've experienced that sounds remotely similar to what you're experiencing is if you delete the 'releaseall' command at the end of the @PedometerScript pointer. If you do that, the player will lock up while the pedometer will add a step every single frame until it reaches 600 steps. Even if you haven't deleted it, could you open your emulator's memory viewer, select 'automatic update', go to 0x203B7C4 and then run your script in-game? If you see the value at 0x203B7C4 rise every frame then we have our culprit, if not, there's another idea we could try.
     
    65
    Posts
    8
    Years
  • Hi, 0x203B7C4 doesn't rise. A friend of mine is now working on a Timer-Script based on your idea, but it would still be great if we could solve that issue to also make such a Pedometer-Script. I can imagine an application of this script for a puzzle, which you can only solve with a certain amount of steps :)

    And I haven't deleted the releaseall-command
     
    853
    Posts
    3
    Years
    • Seen Nov 9, 2023
    Hi, 0x203B7C4 doesn't rise. A friend of mine is now working on a Timer-Script based on your idea, but it would still be great if we could solve that issue to also make such a Pedometer-Script. I can imagine an application of this script for a puzzle, which you can only solve with a certain amount of steps :)

    That type of script already exists(I believe), that's the deoxys puzzle from fire red/leaf green.

    Also did you check this part of the cfru doc?
    Screenshot (728).png

    If it can already return/keep track of the number of steps you walk that should be everything you need already.
     
    65
    Posts
    8
    Years
  • Hi,

    I checked the Deoxys Puzzle, but I don't understand how this script works (I suppose it's the Lv.5-Script). special2 LASTRESULT 0xB4 (Does that mean The Step-Counter is set to 180 steps?), then compare LASTRESULT 0x7 (why 7?), then if 0x5 goto @aReturnPointer (why 5? And why does it goes to a Pointer which's purpose is just to return the the script?).

    Yes, I checked the CFRU Manual, but this doesn't help me like many times, it's not detailled enough (at least for newcomers I guess). F.ex. The Screenshot only tells how to turn the Pedometer on or give it a predefined max-number (not a specific exact number like f.ex. 160, you have to take 255 then) and the doc doesn't write how to compare the steps walked to the pedometer.

    But if we could unravel how the Deoxys-Puzzle-Script works, that would already be very helpful :)
     
    853
    Posts
    3
    Years
    • Seen Nov 9, 2023
    Hi,

    I checked the Deoxys Puzzle, but I don't understand how this script works (I suppose it's the Lv.5-Script). special2 LASTRESULT 0xB4 (Does that mean The Step-Counter is set to 180 steps?), then compare LASTRESULT 0x7 (why 7?), then if 0x5 goto @aReturnPointer (why 5? And why does it goes to a Pointer which's purpose is just to return the the script?).

    Yes, I checked the CFRU Manual, but this doesn't help me like many times, it's not detailled enough (at least for newcomers I guess). F.ex. The Screenshot only tells how to turn the Pedometer on or give it a predefined max-number (not a specific exact number like f.ex. 160, you have to take 255 then) and the doc doesn't write how to compare the steps walked to the pedometer.

    But if we could unravel how the Deoxys-Puzzle-Script works, that would already be very helpful :)

    Did you try the example script with the special I screenshotted because that's exactly what the script is supposed to do.

    The special reads the current value of the pedometer you have active stored in lastresult, and the buffer value will display that value in readable text.

    special2 LASTRESULT 0xB4 (Does that mean The Step-Counter is set to 180 steps?)
    no that's just value of the special to call.

    special 0x84, it has nothing to do with the number of steps, I haven't looked at the script myself, but I'd assume that special is the comparison for how many steps the player has taken, compared to the ideal number of steps to reach the triangle.


    Also if you don't quote me in your response I won't get a notification.
     
    65
    Posts
    8
    Years
  • Did you try the example script with the special I screenshotted because that's exactly what the script is supposed to do.

    The special reads the current value of the pedometer you have active stored in lastresult, and the buffer value will display that value in readable text.

    no that's just value of the special to call.

    special 0x84, it has nothing to do with the number of steps, I haven't looked at the script myself, but I'd assume that special is the comparison for how many steps the player has taken, compared to the ideal number of steps to reach the triangle.


    Also if you don't quote me in your response I won't get a notification.


    I've tried the CFRU Example Script out (as a Level2-Script, it has to be a Level-Script), but I wasn't successfull. The script either ends directly or the first msgbox loops infinitly.


    Here's my updated Script:

    #dynamic 0xA30000

    #org @start
    msgbox @LetsStart 0x6

    setvar 8004 0x3
    special2 LASTRESULT 0x8A
    buffernumber 0x0 LASTRESULT
    if 0x3 goto @MaxStepsReached
    release
    end

    #org @MaxStepsReached
    msgbox @Finished 0x6
    setvar 0x5011 0x1
    warpmuted 0x3 0x5 0xFF 0x7 0xB
    release
    end

    #org @LetsStart
    = Ok, let's start!

    #org @Finished
    = Time's up[.]
     
    853
    Posts
    3
    Years
    • Seen Nov 9, 2023
    I've tried the CFRU Example Script out (as a Level2-Script, it has to be a Level-Script), but I wasn't successfull. The script either ends directly or the first msgbox loops infinitly.


    Here's my updated Script:

    #dynamic 0xA30000

    #org @start
    msgbox @LetsStart 0x6

    setvar 8004 0x3
    special2 LASTRESULT 0x8A
    buffernumber 0x0 LASTRESULT
    if 0x3 goto @MaxStepsReached
    release
    end

    #org @MaxStepsReached
    msgbox @Finished 0x6
    setvar 0x5011 0x1
    warpmuted 0x3 0x5 0xFF 0x7 0xB
    release
    end

    #org @LetsStart
    = Ok, let's start!

    #org @Finished
    = Time's up[.]

    Did you setup your pedometer first?
    and I don't know much about level script, I would just use regular event scripts to test if it works before doing anything more complex.

    You need to set the flag for the pedometer you want.
    Then use the other script to check its current result.

    also this part...
    if 0x3 goto @MaxStepsReached

    isn't doing with you think it is, and is prob part of the problem, you're putting a comparison command after a buffer, that's not going to do anything. Which of course would make it skip the goto and just end.

    Look you need to take a step back here, and take some time to get better at scripting before you try tackling this.

    Here's a good tutorial.
     
    65
    Posts
    8
    Years
  • Did you setup your pedometer first?
    and I don't know much about level script, I would just use regular event scripts to test if it works before doing anything more complex.

    You need to set the flag for the pedometer you want.
    Then use the other script to check its current result.

    also this part...
    if 0x3 goto @MaxStepsReached

    isn't doing with you think it is, and is prob part of the problem, you're putting a comparison command after a buffer, that's not going to do anything. Which of course would make it skip the goto and just end.

    Look you need to take a step back here, and take some time to get better at scripting before you try tackling this.

    Here's a good tutorial.

    So I need to make one Lv2-Script with this line only: (setvar 8004 0x3) and then another one with the rest? I don't want to erase the buffer as it would be very comfortable for Players to see the number of Steps they've taken to determine, how many steps they have left. So how does the comparision and buffer work?

    And thanks for the Tutorial. I already knew most of the parts, but there are certain things I didn't knew and they were quite interesting :)
     
    853
    Posts
    3
    Years
    • Seen Nov 9, 2023
    And thanks for the Tutorial. I already knew most of the parts, but there are certain things I didn't knew and they were quite interesting :)

    You're welcome, but what I wanted you to look at was the proper order for using conditional statements like ifs
    and how specials and lastresult work. Guess I should have been more specific. and briefly no I don't mean put 8004 0x3 separately I mean actually set the pedometer, I don't know how (I assume you have to write it into the C files instead of using xse) but in cfru its set with flags seen here.
    Screenshot (796).png

    setvar 8004 0x3
    special2 LASTRESULT 0x8A
    buffernumber 0x0 LASTRESULT
    if 0x3 goto @MaxStepsReached
    release

    in this script yourseteting 8004 to 0x3

    next you're using special2 to assign lastresult aka 800D the value "Stored in" 0x8a , (or something like that, its based on specials work)
    buffernumber 0x0 lets that value be shown as text via [buffer1] in your script.

    The problem I was trying to allude to, is that if command.

    if 0x3 goto.

    if what is 0x3? because of the placement its either referring to the buffernumber or the value of lastresult neither of which is what you want.
    because the only time they will be 0x3, is if you have only taken three steps, or maybe you only have three steps left on the count depending on how it works.

    I guess you can see now why the script fails.
    Because the value is isn't 3, it never triggers the goto, so it jumps it, and just goes straight to release end.

    Also to make sure I'm clear on something buffer will only ever show the value if you have literally wrote [buffer] into a msgbox script.

    That part is also in the tutorial but I'll give a little brief here.
    buffer 0x0 is the first buffer slot it equates to [buffer1] there's no real limit (far as I know) to how many buffers you can have per script.

    You can set the hex value to whatever you want I think, and as long as your message box refers to the right buffer slot (the hex value +1) it should work no matter what.

    ex. buffernumber 0x6 would correspond to buffer7.

    So if you wanted something really complex, you could buffer a species/or player/npc name to 0x0
    set step count to 0x1.
    buffer each name of your party pokemon to buffer 0x2-7.
    and have a script that's essentially all buffers lol

    = [buffer1] walked [buffer2] steps!\n With [buffer2],[buffer3],[buffer4],\p[buffer5],[buffer6] &\n[buffer7] in their party.

    Extreme yes, but that's an example of how the buffers work, I said that because you don't appear to have an buffer output anywhere in your scripts.
     
    65
    Posts
    8
    Years
  • You're welcome, but what I wanted you to look at was the proper order for using conditional statements like ifs
    and how specials and lastresult work. Guess I should have been more specific. and briefly no I don't mean put 8004 0x3 separately I mean actually set the pedometer, I don't know how (I assume you have to write it into the C files instead of using xse) but in cfru its set with flags seen here.
    View attachment 96204

    setvar 8004 0x3
    special2 LASTRESULT 0x8A
    buffernumber 0x0 LASTRESULT
    if 0x3 goto @MaxStepsReached
    release

    in this script yourseteting 8004 to 0x3

    next you're using special2 to assign lastresult aka 800D the value "Stored in" 0x8a , (or something like that, its based on specials work)
    buffernumber 0x0 lets that value be shown as text via [buffer1] in your script.

    The problem I was trying to allude to, is that if command.

    if 0x3 goto.

    if what is 0x3? because of the placement its either referring to the buffernumber or the value of lastresult neither of which is what you want.
    because the only time they will be 0x3, is if you have only taken three steps, or maybe you only have three steps left on the count depending on how it works.

    I guess you can see now why the script fails.
    Because the value is isn't 3, it never triggers the goto, so it jumps it, and just goes straight to release end.

    Also to make sure I'm clear on something buffer will only ever show the value if you have literally wrote [buffer] into a msgbox script.

    That part is also in the tutorial but I'll give a little brief here.
    buffer 0x0 is the first buffer slot it equates to [buffer1] there's no real limit (far as I know) to how many buffers you can have per script.

    You can set the hex value to whatever you want I think, and as long as your message box refers to the right buffer slot (the hex value +1) it should work no matter what.

    ex. buffernumber 0x6 would correspond to buffer7.

    So if you wanted something really complex, you could buffer a species/or player/npc name to 0x0
    set step count to 0x1.
    buffer each name of your party pokemon to buffer 0x2-7.
    and have a script that's essentially all buffers lol

    = [buffer1] walked [buffer2] steps!\n With [buffer2],[buffer3],[buffer4],\p[buffer5],[buffer6] &\n[buffer7] in their party.

    Extreme yes, but that's an example of how the buffers work, I said that because you don't appear to have an buffer output anywhere in your scripts.

    Thanks for that explanation of the buffer-command :) I was thinking that it might have an automatical output 😅

    I figured out that the Safari-Pedometer in the CFRU-Doc might be a solution. So, I made those 2 Lv2-Scripts:

    Script A - Step Counter Activation
    Spoiler:


    Script B - Check Results
    Spoiler:


    The problem is that I get a messagebox with weird characters. And no, I haven't forgotten to set #raw word 0xFFFF to 0x0 in both Level2-Scripts.

    I suppose the setflag 0x921, because I hadn't set it before, but there the Script wouldn't execute after 50 steps or more.

    I have really no idea what causes this problems ... Has the Script A to be a different Level-Script?

    Thanks for the help :)
     
    853
    Posts
    3
    Years
    • Seen Nov 9, 2023
    Thanks for that explanation of the buffer-command :) I was thinking that it might have an automatical output 😅

    Unfortunately no, you need to use buffers to output any values.

    But my question is where are you getting 921 from as your flag?
    that value isn't in the cfru guide at all.

    Ok I don't think you got what I meant about setting the pedometer flags.

    THIS, is the flag for the pedometers

    FLAG_LONG_PEDOMETER

    literally all of that.
    So at this point it seems like you haven't actually set a pedometer, and are trying to call something that doesn't yet exist.

    Which would cause very messed up text and or graphics. (I've done it before myself *nod*) [forgot what rom I was using once, and tried to run a script pointing to a table
    that hadn't been created on that rom.]

    Anyway, level script isn't your issue, what you need to do is go into a function in one of the cfru files, and write that pedometer in, so its triggered with the activity you're trying to use it for. After that you can use a level script to check the results.

    Or...maybe you can redefine it in the cfru files, and set it so you can actually call it with a specific flag?

    Unless you've already figured out how to do that?

    If you did do that, I don't know what's wrong.
     
    65
    Posts
    8
    Years
  • Unfortunately no, you need to use buffers to output any values.

    Anyway, level script isn't your issue, what you need to do is go into a function in one of the cfru files, and write that pedometer in, so its triggered with the activity you're trying to use it for. After that you can use a level script to check the results.

    Or...maybe you can redefine it in the cfru files, and set it so you can actually call it with a specific flag?

    Unless you've already figured out how to do that?

    If you did do that, I don't know what's wrong.

    Hmmm... I actually hoped to get some Skeleton-/Template Script, as I haven't made a Dungeon-Room that makes use the Step-Counter, but I would, once it would have worked and I'm not very experienced in messing up with CFRU-Files.

    Ok, take your time :) Anyways thank you for the help :)
     
    853
    Posts
    3
    Years
    • Seen Nov 9, 2023
    Thanks for that explanation of the buffer-command :) I was thinking that it might have an automatical output 😅

    I figured out that the Safari-Pedometer in the CFRU-Doc might be a solution. So, I made those 2 Lv2-Scripts:

    Script A - Step Counter Activation
    Spoiler:


    Script B - Check Results
    Spoiler:


    The problem is that I get a messagebox with weird characters. And no, I haven't forgotten to set #raw word 0xFFFF to 0x0 in both Level2-Scripts.

    I suppose the setflag 0x921, because I hadn't set it before, but there the Script wouldn't execute after 50 steps or more.

    I have really no idea what causes this problems ... Has the Script A to be a different Level-Script?

    Thanks for the help :)

    Ok, now that I've actually taken the time to look, yeah I see several problems.

    1. set flag 0x921 you're setting a pedometer
    2. then you (not blaming you for this one, I see the cfru guide literally says do it that way) set var 8004 using a decimal value and not a hex. (needs the 0x0)

    2.a. ok so I've never seen a last result use a non-hex value I'm just assuming the guide is wrong here, but he literally has the value written exactly the same about 3 times, so I just don't know. but check the actual safari zone code in the game if you can to confirm, but I think you should use the hex value for 50 which is 0x32.

    3. special 89, after setting a pedometer, you set another pedometer, (So you could pedometer, while you pedometer. sorry bad joke)

    4. special 0x81, either I'm understanding it wrong or this is another guide typ0, it says setting to 0, i.e 0x0 will remove any walking script.
    So the default shouldn't be load pointer 0x0 pointer message I'd think it would be 0x1. (actually I have no idea, that thing is written/explained very badly)
    4.1 But either way its not really needed (I think) because getting the result of your cfru pedometer is the job of special 0x8a.

    5. setvar 0x8004 0x2 '-- Tells the special 0x8A that the Pedometer is active, Special 0x8a is no where in your code, so this does nothing.

    6. Ok I see what you were trying to do but....you mixed specials for 2 separate pedometers together, specials aren't like regular scripts that you can mix and match with different things for different effect, specials have to be called and used in the specific way that they're meant to, or they just won't work.

    special2 LAST_RESULT 0x88 'Get current pedometer
    Compare LAST_RESULT 50
    If 0x3 goto @Continue
    setvar 0x8004 50 'Pedometer can only reach 50 steps
    Special 0x89 'Set the safari step counter to 50

    So replacing the top line with the other pedometer
    using the second line set value for the safari pedometer/which isn't at all apart of the syntax for the cfru pedometer
    Just won't work.

    #org @PedometerScript
    setvar 0x8004 0x2 '-- Tells the special 0x8A that the Pedometer is active
    special2 LASTRESULT 0x88 '-- Get current pedometer
    compare LASTRESULT 50
    if 0x4 goto @MaxStepsReached
    releaseall
    end

    Same problem as stated above.


    7. setting special 0x88 before and separate from 0x89

    This one was very confusing and I had to stare at it in the cfru guide for a while before it started making sense. 0x88 gets the value of the safari pedometer, but special 0x89 is what actually sets the safari pedometer and its value. Didn't make sense, until I realized its because these two are always meant to be used together in one script. You should never have special 0x88 byitself.

    that's the portion that checks your safari steps and I believe displays it.

    So an entire safari script should be

    special2 LAST_RESULT 0x88 'Get current pedometer
    Compare LAST_RESULT 50
    If 0x3 goto @Continue
    if 0x4 goto @OverFifty
    setvar 0x8004 50 'Pedometer can only reach 50 steps
    Special 0x89 'Set the safari step counter to 50

    actually no that doesn't make sense to me, either.

    Like if the script was written that way, I'd assume it would just never set the pedometer unless its supposed to loop? But even that doesn't work because it would
    reset the safari counter probably each step and never get to 50...

    Ok I'm assuming the example script is just completely wrong at this point.

    Just check the safari zone actual script and lvl scripts.

    But I'd assume it should be setvar 0x8004 0x32 and then special 0x89 and then put special 0x88 in another script with the compare and two if statements to pull results.






    Alright that's all I could get out of that. oh and also I don't know if the safari zone pedometer is locked to one map, or can be used anywhere, but still you should just use the regular cfru pedometer. You can't mix the implementations together.
     
    Last edited:
    Back
    Top