Discussions

SmileBASIC Community

falnshowerTheFinalAct1

09/07/2016 1:51 PM ·Spoilers

Open Closed

How to split a numerical variable?

Does anyone know how to split a numerical value with a maximum of 5 characters (maximum amount of 99999) into five seperate variables? I want to make a sprite based counter for my game.

Advertisement

Comment

This post has no comments.

  • Use the DIV and MOD instructions. DIV returns the integer division of two values and MOD returns the remainder of the integer division. You can employ these two operators in a way that you can get each individual digit in a number. For example... 10298 MOD 10 will return 8. 10298 DIV 10 will return 1029. 1029 MOD 10 will return 9. 10298 DIV 100 will return 102. Etc.

    Yeahs2
    Played
  • Okay, thanks

    Yeahs0
  • Attached is some example code.

    Yeahs1
    Played
  • This might be easier: DEF DIGITS N% OUT A%,B%,C%,D%,E% VAR S$=FORMAT$("%05D",N%) A%=VAL(S$[0]) B%=VAL(S$[1]) C%=VAL(S$[2]) D%=VAL(S$[3]) E%=VAL(S$[4]) END

    Yeahs0
    Played

Add a Comment

You must sign in to post a comment.

Sign in using a Nintendo Network ID to connect to users around the world by writing posts and comments and by giving Yeahs to other people's posts. You can create a Nintendo Network ID using your Wii U console or your system in the Nintendo 3DS family.

Use of Miiverse Details about Miiverse

Report Violation to Miiverse Administrators

You are about to report a post with content which violates the Miiverse Code of Conduct. This report will be sent to Nintendo's Miiverse administrators and not to the creator of the post.

Violation Type:

Post ID: 3DB-NBL7-EJ9-9E2E-Y7L-69R3

Report Violation to Miiverse Administrators

You cannot report posts made automatically by a software title.

Edit Post

Select an action: