How do I use a text global variable to reference a numerical

Get help using Construct 2

Post » Thu Feb 09, 2017 11:21 pm

I am trying to make it so that when you have the resources available to buy a building, that a "!" becomes visible over the build icon. To do this I have a few global variable, but the issue that I am having is that the text variable will not reference the numeric variable.

Here is my example.

Global Variable
Wood (#)
UpgradeQuantity (#)
UpgradeResource (TEXT)

My code goes like this
Wood=1
UpgradeQuantity=1
UpgradeResource=Wood

Everytick
UpgradeQuantity <= UpgradeResource Set "!" to visible

How to I make it so that when it reads "UpgradeResource" that it see's "Wood" and then references the Wood Variable?
B
6
Posts: 5
Reputation: 262

Post » Fri Feb 10, 2017 12:16 am

I guess you could put the requirement on the building object itself as an instance variable. This is how I would do it:

So on the building object, an instance var :
WoodRequired : 1

Then global variables :
TotalWood : 1

Then to upgrade :
For building, if WoodRequired <= TotalWood, Set ! to visible
B
46
S
16
G
73
Posts: 2,084
Reputation: 43,677

Post » Fri Feb 10, 2017 2:38 am

I will try this, thanks.
B
6
Posts: 5
Reputation: 262

Post » Fri Feb 10, 2017 4:41 pm

I tried your solution and I don't think it works for my game. The issue is that I want to be able to have the global variable tell the formula which resource is being used. This way when it does upgrade I Can change what resources it needs to get to the next level.

When the building levels it is going to change what resource and quantity is required for next level, so right now "UpgradeResource" is set to wood, but next level it will be turned into say, water. So I really need to figure out a way that when the compare variable reads "UpgradeResource" it actually points to the "Wood" Global variable.
B
6
Posts: 5
Reputation: 262

Post » Fri Feb 10, 2017 6:13 pm

Use a Dictionary. Add keys, assign values to keys.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Feb 10, 2017 6:27 pm

Never used dictionary, now sure how that will work.
B
6
Posts: 5
Reputation: 262

Post » Fri Feb 10, 2017 6:38 pm

Can I use dictionary text string to call a global variable? Cause the resources are all global variables.
B
6
Posts: 5
Reputation: 262

Post » Fri Feb 10, 2017 7:38 pm

Global variable UpgradeResource (text) = "Wood" (or whatever is required for a level)
Global variable NeededResources (number) = required amount

Add all the resources as keys to an dictionary, assign values, and update them while gathering resources.

Now you can ...

Dictionary > Compare value > Key = UpgradeResource ... > .. Value = NeededResources
__________action ... level up

That, ofcourse, works fine until you need more 'NeededResources' to level up. At one point you could feel the need to level up when there is 500 wood and 1200 iron gathered.

Then you come back, and i will advise you to not use that logic that you so really want to use at this point. Just bring it all in 1 array.

Alternative. You can make a global for each resource, holding whats needed to upgrading.

Global 'wood' = 20
Global 'iron' = 0
Global 'meat' = 55

Using a dictionary .....

Dictionary > Compare value > Key = "wood" (a string) ... > .. Value = 'wood' (the global) - 1
Dictionary > Compare value > Key = "iron" ... > .. Value = 'iron' - 1
Dictionary > Compare value > Key = "meat" ... > .. Value = 'meat' - 1
_______actions whatever you want to do to perform a level up

Arrays & Dictionaries are just, and not more then, a variable holding more values. You should not shy away from them.
You will need them for 100 % sure at one point. Can as well start using now in a not to complicated logic.

Want to stay with the concept of globals. No problem. Just cant do that logic that you so weirdly want to do.

3 Globals.
1 for each resource, holding whats needed to upgrading.

Global 'LvUwood' = 20
Global 'LvUiron' = 0
Global 'LvUmeat' = 55

3 Globals.
1 for each current gatherd resource.

Global 'CuRwood' = updating while gathering
Global 'CuRiron' = updating while gathering
Global 'CuRmeat' = updating while gathering

System compare 2 values > 'Curwood' > 'LvUwood' -1
System compare 2 values > 'CuRiron' > 'LvUiron' -1
System compare 2 values > 'CuRmeat' > 'LvUmeat' -1
_____________Actions .... level up
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: David181, Shenkai the ssj, tatogame, Yahoo [Bot] and 18 guests