|
Axe Software Forums
Quest Developer Forum Trying to reach numeric value...
|
Author | Topic: Trying to reach numeric value... |
Computer Whizz |
posted 01-11-2002 20:25 GMT
Hi, here's my problem... I have a numeric variable set up to display the ammount of 9mm bullets the player has (another one could be used for shotgun rounds, grenade bullets, ect...) and this is a constant name... Now I have a variety of guns, a hand gun, a shot gun, a grenade gun ect... The player "arms" a gun, and when he tries to shoot I want to check that the bullets for the armed gun is above 0. if (%$objectproperty(#armed#; BULLETS)$% > 0) But, not surprisingly, it didn't work... I was just wondering if there were a way to get the name of a variable from the property of an object, and refer to it in the If statement without using LOADS of if's... Computer Whizz |
MaDbRiT |
posted 01-11-2002 21:25 GMT
Hi C.W. I haven't time to check this at present, but I know when writing my libs I hit a similar snag with properties read in this way not "testing" as you might expect. So what I did was assign the property to a numeric variable, and test that - seemed to work for me! Try:
quote:
|
Computer Whizz |
posted 01-11-2002 23:01 GMT
Well, thanks MaD, but it doesn't give me any more help... What I want to do it get the value from my #(armed);bullets# and then use THAT to point me to another variable. I remember a discussion before where Alex said "Theoretically one could use one variable to point to another's name" and that's basically what I'm trying to do... Using the property, to store the name of a different variable, and get the value from that variable. Computer Whizz |
Alex |
posted 02-11-2002 08:55 GMT
Numbers from object properties should work properly in an "if", as far as I know. CW, with those "%" characters, are you trying to get the "if" to refer to a variable named by a property? That won't work because Quest processes numeric variables before processing functions (as you might pass a numeric variable to a function, but you shouldn't be trying to pass a function to a numeric variable!) - so Quest will be looking for a numeric variable that is actually named "$objectproperty(#armed#; BULLETS)$" - if you look in the ASL log you'll probably see it complain that it doesn't exist. Why not just have the "bullets" property be a number anyway - then you could use (with the shorter syntax): if ( #(armed):BULLETS# > 0) ... |
MaDbRiT |
posted 02-11-2002 09:13 GMT
Alex wrote:-
quote: I agree they should :-) but some time back when working on my library I found that I had to to the job in two stages (assign the property to a numeric specifically then test) for the test to work reliably. You may well have eliminated the need to do this now, but I confess that having found a method that worked, I've stuck to it ever since... Alex, it seems you and I both 'didn't get' what C.W. was trying to achieve with his code here. I have to say that any piece of code logic that requires a variable to store the name of another variable would cause me to frown really hard - and then look for ways to re-write it so that it didn't! Al |
Computer Whizz |
posted 02-11-2002 23:53 GMT
Well, really what I want is this; A variety of guns that can handle different kinds of ammo... Different kinds of ammo stored seperatly... If I used the object property for the ammo, then if you had different guns you would have to change the property in ALL the guns you had through-out the game... This way, the ammo is kept as a seperate ammount, and when the gun is to be used then it finds it's own type of ammo and uses it. It was basically for a little demo on "moving monsters" that I was doing... For the demo I could just use the variable's name - but if you wanted a game with LOADS of guns, with numerous types of ammo then you would need to match up the different guns with the different ammo... That was what I was trying to do. Have a gun, with the property holding the name of the variable where the ammo is. Alex - you are correct... Could I do it if I were to put the variable name, from the property, into another variable and use THAT to get the value? I am aware that the log file was searching for the variable $objectproperty....$. Computer Whizz |
MaDbRiT |
posted 03-11-2002 09:09 GMT
Forgive me if I am missing something obvious here, but surely if you have 3 types of gun, say a 9mm automatic, a shotgun and a grenade launcher, using a property 'ammunition' in each object to store the relevant quantities of 9mm bullets (in 9mm automatic ammunition property), cartridges (shotgun ammunition property) and grenades (grenade launcher ammunition property) would circumvent the problem at source? This way using a variable to hold the name of the weapon currently in use, checking relevant ammunition is available is the dead simple:- if (#(currentweapon):ammunition# >0) (Where #currentweapon# contains the name of the current weapon in use obviously.) If you have weapons that can each fire multiple types of ammunition, then I can see why you'd store the ammo in discrete variables, otherwise storing the ammo in its relevant weapon properties must surely be the way to go? Assuming for a moment you do want 'multi-ammo' weapons and need to store the ammo seperately, I would have thought an ammunition array, ammo(1) = 9mm, ammo(2) cartridges etc, was the way to go, using a control variable as an index to cycle through the available ammo to check availability of all the ammo types for the current weapon in one small loop rather than a whole mass of "if thens" on seperate variables! Al Al |
MaDbRiT |
posted 03-11-2002 09:20 GMT
AHA! Re-read your post for n'th time and finally grasped what you are trying to do C.W.! Suggestion... Use an ammo array variable to store all your different ammunition as I suggested in the last posting.. say 9mm shells are counted in ammo(1), shotgun shells in ammo(2) Set a property of each weapon to hold the index number of the relevant ammo type. a 9mm handgun would have property ammotype=1, shotgun would have property ammotype=2. Then you can use a comparison to check if there is any of the right ammo for the currently in use weapon. I have a nasty feeling that the forum will not let me post the actual code here though as arrays use square brackets! So basically you'd check the ammo array (index) where index is read from the current weapon's ammotype property to see if there was any appropriate ammo. I hope I've now 'got the idea' after a few tries.. LOL Al |
Computer Whizz |
posted 04-11-2002 14:22 GMT
Ah.... Yes, I get the idea. Thank you MaD. Computer Whizz |