• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML split equation into numbers and operator

A

AkjoHD

Guest
I want to split an equation into 3 sections. The first number, the second number and the operator itself.

Example:
Input (string_print) = print 10+15
num1 = 10
num2 = 15
op = "+"

Code:
eq = string_copy(string_print, 7, string_length(string_print)-6)
This is the code I use for getting everything after the "print ".
 

chamaeleon

Member
I want to split an equation into 3 sections. The first number, the second number and the operator itself.

Example:
Input (string_print) = print 10+15
num1 = 10
num2 = 15
op = "+"

Code:
eq = string_copy(string_print, 7, string_length(string_print)-6)
This is the code I use for getting everything after the "print ".
Use the string_pos function to find the offset of your operator and use string_copy in conjunction with that to extract the number values. I'm sure you realize at this point string functions are not GMS strong suit. You'll either painstakingly build it yourself using the barebones functionality, or search the marketplace for a suitable extension (perhaps a regular expression extension, if one exists that offer the required functionality and target platform support).
 
A

AkjoHD

Guest
Use the string_pos function to find the offset of your operator and use string_copy in conjunction with that to extract the number values. I'm sure you realize at this point string functions are not GMS strong suit. You'll either painstakingly build it yourself using the barebones functionality, or search the marketplace for a suitable extension (perhaps a regular expression extension, if one exists that offer the required functionality and target platform support).
Thanks for the help! String functions are definitely not GMS strong suit but I still will try it out tomorrow.
 
Top