User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13

Thread: Splitting a value

  1. #1
    Clicker Multimedia Fusion 2iOS Export ModuleXNA Export Module
    Asholay's Avatar
    Join Date
    Nov 2008
    Location
    England
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Splitting a value

    I'm saving a Global Value as a 4 digit number to represent 4 different resource values you collect when you collide with a special resource block.

    The 4 digits represent a modifier to each of your 4 resources, e.g. 1221 would translate into +1 gold, +2 for blue & green and +1 purple.

    When you collide with the special block, I'm adding the Global value to the resource, but taking just the appropriate digit - so on your gold counter, I need the first digit of the global value, for blue I need the 2nd digit.

    How can I do this with a simple expression, and without converting to a string or use fast loops. Also this is an XNA project, so I have access to limited extensions.


    edit: I tried it with a string conversion and it works okay (add to counter: Val(Mid$(Str$(Global Value), 0, 1))), but is this bad coding? Converting a value to a string, taking part of that string and reconverting to a value..? Seems a bit roundabout to me and I'm trying to avoid clogging the engine again.

  2. #2
    Clicker Fusion 2.5 DeveloperFusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleXNA Export Module
    DistantJ's Avatar
    Join Date
    Jan 2008
    Location
    Gloucester, UK
    Posts
    2,144
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Splitting a value

    I was going to say to use Val and Str$ as well, it's the simplest way and a decent expression. It can also be done with math but I would be worried about it rounding up from a decimal point and some numbers coming out wrong.

    Have you considered using a global string instead? Using Str$ when appending to it and Val when retrieving?

  3. #3
    Clicker Multimedia Fusion 2iOS Export ModuleXNA Export Module
    Asholay's Avatar
    Join Date
    Nov 2008
    Location
    England
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, that's a good way of taking one of the processes out, cheers.

  4. #4
    Clicker Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleXNA Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    gkinfinity's Avatar
    Join Date
    May 2011
    Location
    USA
    Posts
    284
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I just made a quick and poorly done example. Is this what you're looking for?
    Attached files Attached files

  5. #5
    Clicker Multimedia Fusion 2iOS Export ModuleXNA Export Module
    Asholay's Avatar
    Join Date
    Nov 2008
    Location
    England
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice one gkinfinity - I was worried that dividing and multiplying would have rounding issues, but your method is absolutely spot on! Thanks for taking the time to make an example.

  6. #6
    Clicker Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleXNA Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    gkinfinity's Avatar
    Join Date
    May 2011
    Location
    USA
    Posts
    284
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You're welcome! I'm pretty sure the decimal is completely truncated so I don't think it'll be a problem.

  7. #7
    Clicker Fusion 2.5 DeveloperFusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleXNA Export Module
    DistantJ's Avatar
    Join Date
    Jan 2008
    Location
    Gloucester, UK
    Posts
    2,144
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Splitting a value

    If that's the case then the math way is even better! I was worried that for example 1469 would come out as 1, 4, 7, 9 due to rounding up the resulting .9

  8. #8
    Clickteam Clickteam
    Danny's Avatar
    Join Date
    Aug 2007
    Location
    United Kingdom
    Posts
    3,016
    Mentioned
    21 Post(s)
    Tagged
    2 Thread(s)
    You could just use a String to store the values with a delimiter... would be much easier and faster.

    #1#2#2#1 (Get Element)1,2,3,4
    Want to learn Clickteam Fusion 2.5?




  9. #9
    Clicker Fusion 2.5 DeveloperFusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleXNA Export Module
    DistantJ's Avatar
    Join Date
    Jan 2008
    Location
    Gloucester, UK
    Posts
    2,144
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Splitting a value

    Danny's method is handy because you can have however many digits you want per each of the 4 values, but it depends what exporters you are using, you need to make sure there is a function to "explode" the string or read it off in an extension compatible with your chosen runtime. It can be done with fast loops but then it becomes kinda inefficient.

  10. #10
    Clicker Multimedia Fusion 2iOS Export ModuleXNA Export Module
    Asholay's Avatar
    Join Date
    Nov 2008
    Location
    England
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DistantJ View Post
    If that's the case then the math way is even better! I was worried that for example 1469 would come out as 1, 4, 7, 9 due to rounding up the resulting .9
    I was as well, but no matter how hard I tried, I couldn't get infinity's example to give a flawed reading!

    Quote Originally Posted by Danny View Post
    You could just use a String to store the values with a delimiter... would be much easier and faster.

    #1#2#2#1 (Get Element)1,2,3,4
    I was trying to avoid external extensions because I'm worried of bugs creeping in, and the more I stick to simple in-built solutions the better, but if you're suggesting it would perform quicker then I'm certainly in favour.

    Actually Danny, I had another performance question - you know in my file, I've got the garage screens split into 2 - one which shows the upgrade on your toolbar, and the other which shows the price of the upgrade - I was thinking of switching the smaller box to a single active which appears & disappears (as a 'backdrop') and 4 counters for the 4 resources. This way I can grab the price data from the array, and won't have to redraw everything when I make balance tweaks.

    The question is, which do you think is better for performance? Lots of active frames being loaded into the game and switched, or 4 counters per player. I would be taking over 100 images out of the game by switching to the counter method, but I assume counters are a little hungrier? (bearing in mind this is XNA)

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Is this even possible? (splitting a photo into chunks)
    By Pineapple in forum iOS Export Module Version 2.0
    Replies: 2
    Last Post: 21st August 2013, 07:40 AM
  2. Splitting a variable into it's unique digits.
    By Apex in forum iOS Export Module Version 2.0
    Replies: 2
    Last Post: 13th August 2012, 11:44 AM
  3. Splitting big images into smaller ones
    By ElectricMaster in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 14th March 2012, 09:12 PM
  4. String Splitting?
    By Iharmi in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 20th June 2008, 05:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •