• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code [Solved]real("instance id") becomes 0

R

Re_hei

Guest
I'm making an text engine working by inputting commands in the strings.
(ex: "/name[Player]Hello! My name is \c[c_red]Player!)

I'm trying moving an instance into another instance's position.
For attaching a bubble text box to an character

First, I got the character's instance id in a variable.

message = "/chr[inst_379A98D7] What a nice day."

character_id = string_copy(message, ...) => charater_id = "inst_379A98D7"

Then, I converted the string into a real number.

charater_id = real(charater_id)
[Expected] character_id = inst_379A98D7


However, the variable became 0.

[Done] character_id = 0

Whenever there is 'inst_~~' in ther variable 'charater_id', real(character_id) became 0.
I tried by changing the instance id's name, but even if there was no 'inst~', it became 0, too.

What should I do?
 
  • Like
Reactions: SVG
S

SVG

Guest
Wow that's pretty cool, that's going over my head though unfortunately, makes me want to learn what the heck your doing lol :)
 

GMWolf

aka fel666
Real will convert a string representing a number into a number.
But inst_379A98D7 isnt a (decimal) number,
First step is to strip off th inst_ from the front of the string.
Then, use a hexadecimal to real conversion script: http://www.gmlscripts.com/script/hex_to_dec

Also, it may be, but im not sure that the number following inst_ of the instance name in rolm editor will match the instance id of the object. Something to watch put for if you get strange results later on.
 
R

Re_hei

Guest
Real will convert a string representing a number into a number.
But inst_379A98D7 isnt a (decimal) number,
First step is to strip off th inst_ from the front of the string.
Then, use a hexadecimal to real conversion script: http://www.gmlscripts.com/script/hex_to_dec

Also, it may be, but im not sure that the number following inst_ of the instance name in rolm editor will match the instance id of the object. Something to watch put for if you get strange results later on.
Well.. It doesn't work at all :(
And there are also some instance ids just like inst_7A4236ED. Maybe, I think it is not a hexadecimal problem.

I want a function finding a instance/sound/script... etc in the name of string. Like 'find_instace_id("inst_7A4236ED")'.
 

gnysek

Member
normally, inst_7A4236ED is changed to proper number like 100045 on compile time (if used as constant). There's no inst_7A4236ED when game is running. You can easily check it by running below code:
Code:
show_debug_message(inst_7A4236ED);
and notice it in compile form. There will be a number larger than 10000 for sure.

What you need todo is:
Code:
message = "/chr[" + string(inst_379A98D7) + "] What a nice day."
Which will work as you want :)

Remember: all macros (previously called constants) are changed to proper string/number when compiling, so aren't existing anymore in game! (That's why they are renamed from constants to macros).
 
R

Re_hei

Guest
What part isn't working? Its very hard to help without more info.

And, just to make sure, is inst_7A4236ED something you got from the room editor?
Yes, I got it from the room editor.
I solved this problem. Thank you for your help very much :D

What you need todo is:
Code:
message = "/chr[" + string(inst_379A98D7) + "] What a nice day."
Which will work as you want :)

Remember: all macros (previously called constants) are changed to proper string/number when compiling, so aren't existing anymore in game! (That's why they are renamed from constants to macros).
Wooooooow it works!!
I learned a valuable knowledge. Really Really thank you!!!! :D
 

GMWolf

aka fel666
Yes, I got it from the room editor.
I solved this problem. Thank you for your help very much :D



Wooooooow it works!!
I learned a valuable knowledge. Really Really thank you!!!! :D
Just so you know: you can rename your instances in the room editor so it makes a little more sense to read.
 
Top