The Daily Click ::. Forums ::. Klik Coding Help ::. Variable name question? HARD!
 

Post Reply  Post Oekaki 
 

Posted By Message

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
16th March, 2011 at 11:03:20 -


I have alterable values named "POS_1" through to "POS_10"

Is it possible to set another value to "POS_#"?

Where the # is, an expression.

Say I have an object called counterA. Can I somehow set a value to: POS_"value( "counterA" )" ?

So if counterA = 5 it would set my value to POS_5


Pretty much I am asking if it is possible to pick part of value name based on something else.
Sorry this is really hard to explain.

Any ideas?

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
16th March, 2011 at 11:21:34 -

Use "Alterable value by index". It will ignore the actual names of the alterable values, but it will let you pick one according to another variable.
So, if you rename "Alterable Value A" as "POS_1", "Alterable Value B" as "POS_2", and so on, then you can just say:

AltValN( "Active", value("Counter"))

Or you may be better off using an array, which is really designed for exactly this kind of thing...

 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
16th March, 2011 at 12:52:03 -

Thanks Sketchy.

Cool I didn't know that. But I don't think it fixes my problem.

You said: It will let you pick one according to another variable.

Can this "other variable" be made up of half a string and half a value?. Or does it have to be a lone numerical value. Index.

For example, can it be equal to: "hello" + Value(counter)


Thanks!

Edited by Chris Burrows

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
16th March, 2011 at 14:40:42 -

No, it must be a value.
Why would you need it to be a string?
As long as you order your values sensibly, there's no problem.

And why does it need to be an active object's alterable value?
There are other extensions that would allow you to refer to variables by name (eg. the "named variable" extension). Or you could use the "Value-add" extension.

I just get the feeling that whatever you're ultimately trying to achieve, you might be going about it in a funny way.

 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
16th March, 2011 at 15:00:32 -

Yeah I'm making the item menu for my game and I was going about it a very funny way.

The items are stored using a list object. So when you delete an item you just delete the line from the list.
Using FindStringExact. This way there won't be a gap in the item menu.

There are 12 different slots and 20 items so far. But for each slot, I had to have something like this:

Itemslot_1 = "Handgun" then set Handgun Icon position to x1,y1
Itemslot_1 = "Shotgun" then set Shotgun Icon position to x1,y1
Itemslot_1 = "Crowbar" then set Crowbar Icon position to x1,y1

Itemslot_2 = "Handgun" then set Handgun Icon position to x2,y2
Itemslot_2 = "Shotgun" then set Shotgun Icon position to x2,y2
Itemslot_2 = "Crowbar" then set Crowbar Icon position to x2,y2

... and so on up to 12 for all the items. And that's a lot of code and a real pain for implementing new items into the game.

I was trying to find a way to make it something like
Itemslot_# = "Handgun" then set Handgun Icon position to x#,y#

That way I would only need as many lines of code as there were items.
Instead of as many lines as there are items, multiplied by the amount of slots. 20 items x 12 slots = 240 lines of code. TOO MANY!

BUT! I managed to solve the problem using Qualifiers. Which was much easier.
I've just always hated Qualifiers because you can't change the icon or the name.
And because of this I never think to use them. Cause I hate them. But now I don't mind them.

Thanks for taking the time to help me out. If you're keen on seeing my finished item menu
http://www.whenthereisnoroominhellthedeadwalktheearth.com/NoRoomInHell2.zip (3.2mb)

Hold F1 for the controls.

Thanks again!

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
16th March, 2011 at 15:42:25 -

Okay, here's what I'd do:

In your list of items, use numbers instead of names (keep a reference somewhere).
Have just one kind of active object, representing all the possible items (store each item picture in a different animation frame - frame 0 being blank).
Have 16 duplicates of this object (one for each slot).
Use the "spread value" function to give each object a unique ID.
Then just create an event to set the animation frame of each object to the value at the corresponding line in your list.


btw: I tried your game, and so far it looks great - very polished. Obviously it's still a long way from being completed though.

The thing that immediately occurred to me, was that you shouldn't differentiate between weapons and items - ALL items should be useable as weapons too. You could definitely bash a zombie's head in with a frying pan for example, but even smaller items could be thrown, and might do a little damage.
With something like a bottle, you might be able to attack with it, but then it would be destroyed in the process.

 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
16th March, 2011 at 16:34:21 -


I originally was using that method. But instead of the different instances of the same object, I was using different objects. And instead of different frames, I was using different animations. This was pain staking for implementing new objects so I re-wrote the code for my menu from scratch the way I said in my previous post.

I knew the spread values function existed but didn't know how to use it properly. I just read your article and I get it now though. Thanks!

Either way, I've got it working using the qualifiers method and it is solid as a rock. I only need to add 1 line of code to get a new item to work with the menu and that is far better than 12.

Thanks for your help!

 
n/a
   

Post Reply



 



Advertisement

Worth A Click