Variables: Mixing "strings" And Actual Values, Solved: Thank you |
Novice and intermediate users who are using Drag & Drop action icons, or still learning GML, can get help from more experienced members.
Please READ the Novice Q&A Forum Rules prior to posting. And remember that the General GMC Rules apply here too.
![]() ![]() |
Variables: Mixing "strings" And Actual Values, Solved: Thank you |
Nov 5 2009, 03:37 AM
Post
#1
|
|
|
GMC Member Group: GMC Member Posts: 5 Joined: 5-November 09 Member No.: 144242 |
Hi im new here and I apologise if there is a topic on this already but i cant seem to find it.
I would just like to now how to do this. It will be easier with an example. say i have 2 variables. gun = "pistol" pistol_ammo = 100 How would i make it so I could draw my third variable which would be gun_ammo = gun + "_ammo" and have it draw "100" rather than "pistol_ammo" which is what im getting now. If this doesnt make sense just say ill try re-explain. Thanks Murnane This post has been edited by MurnaneX: Nov 5 2009, 10:33 AM |
|
|
|
Nov 5 2009, 03:46 AM
Post
#2
|
|
|
GMC Member Group: GMC Member Posts: 1933 Joined: 3-October 07 Member No.: 89861 |
Hi im new here and I apologise if there is a topic on this already but i cant seem to find it. I would just like to now how to do this. It will be easier with an example. say i have 2 variables. gun = "pistol" pistol_ammo = 100 How would i make it so I could draw my third variable which would be gun_ammo = gun + "_ammo" and have it draw "100" rather than "pistol_ammo" which is what im getting now. If this doesnt make sense just say ill try re-explain. Thanks Murnane You use the string function to convert real numbers to strings: CODE gun_ammo = gun + string(ammo);
|
|
|
|
Nov 5 2009, 03:52 AM
Post
#3
|
|
|
GMC Member Group: GMC Member Posts: 5 Joined: 5-November 09 Member No.: 144242 |
Hmm yeah i did try that but I still got the same problem of the draw action drawing "pistol_ammo" not 100
|
|
|
|
Nov 5 2009, 04:43 AM
Post
#4
|
|
|
GMC Member Group: GMC Member Posts: 1933 Joined: 3-October 07 Member No.: 89861 |
Hmm yeah i did try that but I still got the same problem of the draw action drawing "pistol_ammo" not 100 It should work if the variables have the values you said. To double check, put the following code in the draw event: CODE gun = "pistol";
ammo = 100; draw_text(x, y, gun+string(ammo)); This post has been edited by jabelar: Nov 5 2009, 04:44 AM |
|
|
|
Nov 5 2009, 05:22 AM
Post
#5
|
|
|
GMC Member Group: GMC Member Posts: 153 Joined: 16-October 09 Member No.: 142831 |
CODE tempvar = gun + "_ammo") gun_ammo = real(tempvar) I just had an idea! Try that. What your current code is doing (gun_ammo = gun + "_ammo") is creating a string, and then it draws the sting. You need to set it as a real value so it recognises it as a variable name, and then draws that. Hope that helps! ND4SPD |
|
|
|
Nov 5 2009, 06:34 AM
Post
#6
|
|
|
GMC Member Group: GMC Member Posts: 1088 Joined: 28-October 06 From: Behind you Member No.: 62579 |
His current code is fine. What he wants is to draw the ammo value of whatever gun he has ("pistol", "bazooka", "sniper", etc) with "_ammo" at the end.
MurnaneX: Just use this code <Draw> CODE draw_text(20,20,gun + "_ammo: " + string(variable_local_get(gun + "_ammo"))); Note: You don't need the first half for your issue, just the string() part, but I thought it would be handy anyways. EDIT: Added string(), just in-case EDIT2: Fixed my first sentence, and added clarification to code. This post has been edited by Shadow Link: Nov 5 2009, 07:00 AM |
|
|
|
Nov 5 2009, 10:32 AM
Post
#7
|
|
|
GMC Member Group: GMC Member Posts: 5 Joined: 5-November 09 Member No.: 144242 |
Thanks guys a heap
|
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 23rd November 2009 - 10:48 AM |