Game Maker Community YoYo Games

Welcome Guest ( Log In | Register )

> Novice Forum Rules

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.

 
Reply to this topicStart new topic
Variables: Mixing "strings" And Actual Values, Solved: Thank you
MurnaneX
post Nov 5 2009, 03:37 AM
Post #1


GMC Member
Group Icon

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
Go to the top of the page
 
+Quote Post
jabelar
post Nov 5 2009, 03:46 AM
Post #2


GMC Member
Group Icon

Group: GMC Member
Posts: 1933
Joined: 3-October 07
Member No.: 89861



QUOTE (MurnaneX @ Nov 4 2009, 07:37 PM) *
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);
Go to the top of the page
 
+Quote Post
MurnaneX
post Nov 5 2009, 03:52 AM
Post #3


GMC Member
Group Icon

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
Go to the top of the page
 
+Quote Post
jabelar
post Nov 5 2009, 04:43 AM
Post #4


GMC Member
Group Icon

Group: GMC Member
Posts: 1933
Joined: 3-October 07
Member No.: 89861



QUOTE (MurnaneX @ Nov 4 2009, 07:52 PM) *
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
Go to the top of the page
 
+Quote Post
ND4SPD
post Nov 5 2009, 05:22 AM
Post #5


GMC Member
Group Icon

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
Go to the top of the page
 
+Quote Post
Shadow Link
post Nov 5 2009, 06:34 AM
Post #6


GMC Member
Group Icon

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 smile.gif
EDIT2: Fixed my first sentence, and added clarification to code.

This post has been edited by Shadow Link: Nov 5 2009, 07:00 AM
Go to the top of the page
 
+Quote Post
MurnaneX
post Nov 5 2009, 10:32 AM
Post #7


GMC Member
Group Icon

Group: GMC Member
Posts: 5
Joined: 5-November 09
Member No.: 144242



Thanks guys a heap
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 23rd November 2009 - 10:48 AM