User Tag List

Results 1 to 3 of 3

Thread: Replace word in Object's String with Global String at runtime

  1. #1
    Clicker Multimedia Fusion 2
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    FlipSwitchX's Avatar
    Join Date
    Feb 2012
    Location
    California
    Posts
    206
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb Replace word in Object's String with Global String at runtime

    Hi there everybody I'm makin' a game where the player set's their name on a save file at the beginning, the name is also stored in a global string. I'm trying to get NPC's to give the correct player name when I type in their alterable strings something like' "Hi playername, how are ya?",(playername is the global string function), but I can't just type that in their alterable string edit box in the editor. I have to do:

    Start of frame -> Set alterable string to "Hi" + playername + "how are ya?"

    I was wondering if there was an easy way around this. Like if there was a secret delimiter that can be typed in the editor to let fusion know the next word is a function and not a word?

    I'm currently trying to start a loop for each object, for each string, for each substring, and compare each substring to "playername" to replace it with playername (the function), but I'm getting caught up on not being able to get a substring via an index. (In this case the loopindex of the substring loop).

  2. #2
    Clicker Multimedia Fusion 2SWF Export Module

    Join Date
    Sep 2006
    Posts
    1,544
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    There are some nice string parsing extensions for MMF2 if you want a rich string editor at runtime, but if all you're doing is replacing one word with a substring, its something you could do with just the built in MMF2 string handling. Under the "special" object, theres a function "Find string in string", which uses the function
    Find(>Enter string to look into<, >Enter string to look for<, >Enter first character<)

    Now what you can do is assemble a simple function that searches every string for the word "playername" before its displayed. If it finds it that function will return the 0-based index of the letter the phrase starts on, and you can retrieve substrings on the left and right of that word, then concatenate the (leftstring + playername + rightstring), replacing it regardless of the length. It gets a bit trickier if you want to let NPC's say the playername more than once, you'd have to make it a loop and do it multiple times (although just recurring the function has the same effect). If "playername" wasn't found, it would return -1, and you just skip the function

    I've created a basic example function for you in MMF2, attached:
    string editor.mfa

    feel free to copy/paste that into your project, no credits needed

    also you'd probably want an additional check of
    if Find(string_to_insert, string_to_replace,0) =/= -1
    then don't let the player use that playername or don't run that function (as it will crash your game)

  3. #3
    Clicker Multimedia Fusion 2
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    FlipSwitchX's Avatar
    Join Date
    Feb 2012
    Location
    California
    Posts
    206
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Thanks Pixelthief, that was insightful

Similar Threads

  1. String Object - Word-Wrap issue
    By Bipolar_Games in forum Fusion 2.5
    Replies: 11
    Last Post: 27th January 2016, 12:04 AM
  2. Individual word by word string comparison?
    By ratty in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 5th May 2013, 05:52 PM
  3. Searching for a word within a string?
    By colej_uk in forum Multimedia Fusion 2 - Technical Support
    Replies: 12
    Last Post: 8th January 2013, 09:04 PM
  4. Changing one word's color in string object
    By NLK in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 26th August 2008, 12:39 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
  •