PDA

View Full Version : Command/Variable Questions



Nimono
02-13-2007, 09:20 PM
Okay, let's go....

1: How do I use the command "int NumNPCs()"? I want to assign this value to a variable "ScrnNPC", but when I compile, I get this error:

"Could not match type signature 'NumNPCs()'"

Here's what I'm doing: "int ScrnNPCs = NumNPCs()" Changing that "int" to "npc" doesn't work.

2: How does "npc LoadNPC(int num)" work, exactly? Again, I want to give the value of this to another variable, "RandNPC".

So you know, I'm trying to make a script that destroys one random enemy when used. Thus, I have to check for the number of enemies on the screen, then modify a random enemy so its HP is 0, thus it gets destroyed. Thing is, most of these, I don't know how to work. Oh, and while I'm thinking about it.... Anyone know how to work "int Rand(int maxvalue)"? I asked jman in chat yesterday, but he told me he wasn't sure how to work it, either.... Help is appreciated.

blue_knight
02-14-2007, 03:11 AM
NumNPCs and LoadNPC are both members of "Screen." So do Screen->NumNPCs(); or Screen->LoadNPC(idx); Remember that LoadNPC is 1 based, meaning 1 is the first NPC - 0 is invalid. I haven't used Rand() yet, I'll try it later and let you know. Does this answer your questions (except for Rand of course)?

DarkDragon
02-14-2007, 03:26 AM
Rand(x) returns some integer y such that 0 <= y < x.
When in doubt, don't forget to check the documentation (http://www.armageddongames.net/forums/showthread.php?t=93851).

Nimono
02-14-2007, 11:54 AM
DarkDragon, I DID check the documentation, but it doesn't tell how to use a single variable there. Basically, it's just saying "Here's the variables, go figure out how to use them yourselves", which I don't like. I'm STILL not sure if I'm using it right....

blue_knight, thank you for helping me out with that variable. I never would've thought to use "Screen->". XD

Edit: But that brings me to another question. When using Rand, how would I make it so there's a specifc MINIMUM value, too? I need a random number so I can load a random enemy to modify, but.... If the Random number ever comes back 0, nothing will happen. How would I make it so it can never come back 0, only numbers 1-10?

Grayswandir
02-14-2007, 12:34 PM
How would I make it so it can never come back 0, only numbers 1-10?

Use floor from std.zh:
Floor(Rand(max - min + 1)) + min


Say you want a number from 1 to 6:
Rand(6 - 1 + 1) is the same as Rand(6), so you will get a number from 0 to 5.9999...
Floor brings that down to an integer from 0 to 5, with an equal chance for each.
Add the minimum value of 1, to get a number from 1 to 6.

Nimono
02-14-2007, 12:39 PM
Ah. How would I set that to another variable? I'm a bit confused here.... If I want the highest number to be 10, I put 11 as the maxvalue? And seriously, tell me how I set that up to set it to a variable RandNum. Please.

DarkDragon
02-14-2007, 02:44 PM
DarkDragon, I DID check the documentation, but it doesn't tell how to use a single variable there. Basically, it's just saying "Here's the variables, go figure out how to use them yourselves", which I don't like. I'm STILL not sure if I'm using it right....

blue_knight, thank you for helping me out with that variable. I never would've thought to use "Screen->". XD

Edit: But that brings me to another question. When using Rand, how would I make it so there's a specifc MINIMUM value, too? I need a random number so I can load a random enemy to modify, but.... If the Random number ever comes back 0, nothing will happen. How would I make it so it can never come back 0, only numbers 1-10?

The documentation is split up by which variable you need to use. Global functions are not associated with any pointer type, so you just plain call them:


int randnumber = 5 + Rand(5); //makes a random number from 5 to 9

any function or variable under the "X Functions and Variables" headings require a pointer of type X. For instance, to use the X that is Link's position, you would do


Link->X = 0; //move link to the right of the screen

Is that what you were asking about? Or are you talking about actual, user defined variables?

For your second question, notice that Rand(y) will give you a number such that 0 <= x < y. But you want 1 <= x < 11, right? So we can do some algebra to calculate what you need to do. To get the correct lower value, we can add 1 to the result (1 + Rand(y)) to get 1 <= x < y+1. Then clearly you want y=10, so


int whatever = 1 + Rand(10);

would get you a number from 1 to 10, inclusive.

Nimono
02-14-2007, 02:49 PM
Thanks! Would the random number return a decimal number, too, or does it only do whole numbers? I'd assume it'd only do whole numbers, but.... Just want to make sure. ;) And thank you for the help.

And by the way, I don't remember WHAT it was I was talking about earlier. XD I'm confused after re-reading my earlier post....

Edit: Oh yeah, what about the HP variable for NPCs? Let's say I wanted variable "Boo" to be a loaded NPC. Would I modify the NPC's HP by using "Boo->HP = whatever", or what?

blue_knight
02-14-2007, 04:55 PM
Yes that is correct. Basically NPCs, FFCs, Items, etc. are pointers to "objects". To access variables and functions that the objects contain ("member variables" and "member functions") you use the "->" operator. Similarly you can access variables from a script (which too is an object), except you use the "." operator. Examples:

Link->X = 0; set the "X" variable of the object "Link"

NPC npc1 = Screen->LoadNPC(1);
npc1->HP = Link->HP; set the "HP" variable of the object "npc1" to the "HP" variable of the object "Link"

Nimono
02-14-2007, 05:02 PM
Yes that is correct. Basically NPCs, FFCs, Items, etc. are pointers to "objects". To access variables and functions that the objects contain ("member variables" and "member functions") you use the "->" operator. Similarly you can access variables from a script (which too is an object), except you use the "." operator. Examples:

Link->X = 0; set the "X" variable of the object "Link"

NPC npc1 = Screen->LoadNPC(1);
npc1->HP = Link->HP; set the "HP" variable of the object "npc1" to the "HP" variable of the object "Link"

Thanks! That helps me out a lot. :)

DarkDragon
02-14-2007, 08:05 PM
Yes, Rand returns integers. You can "fake" returning a decimal by artificially generating extra decimal places:


int whatever = 1 + Rand(10*1000)/1000; //generates a random decimal from 1 to 10.

Nimono
02-15-2007, 10:55 AM
Thanks, but I wanted to make sure Rand would NEVER turn out a decimal. ;)

Okay, new question. How would I check a loaded NPC for a certain set of Enemy IDs? My next script modifies all enemies on-screen by turning them into Gels, but it's not supposed to work on those tough enemies. How would I go about checking this? I'm not sure doing something like "if (Loaded_NPC == 81)" would work (It's also only an example), seeing as the number in the variable would instead be the position of the loaded NPC on the screen's NPC list.... I really need this help. Thank you. :) And yes, I looked through the documentation, and I will keep looking for an answer. ;)

blue_knight
02-15-2007, 05:20 PM
You could check the "Tile" variable of the NPCs. You'll have to figure out a range of tiles, or a set of ranges, and just don't do your effect if the NPC is in one of those ranges. Example:



int nExcludeTileStart=start_tile;
int nExcludeTileEnd=end_tile;

int i;
for(i=1; i<=Screen->GetNumNPCs(); i++)
{
NPC cur_npc = Screen->LoadNPC(i);
if ( cur_npc->Tile < nExcludeTileStart ||
cur_npc->Tile > nExcludeTileEnd )
{
//do your effect here, this NPC is not in the range to exclude.
}
}


Does this make sense?

Nimono
02-15-2007, 05:43 PM
You could check the "Tile" variable of the NPCs. You'll have to figure out a range of tiles, or a set of ranges, and just don't do your effect if the NPC is in one of those ranges. Example:



int nExcludeTileStart=start_tile;
int nExcludeTileEnd=end_tile;

int i;
for(i=1; i<=Screen->GetNumNPCs(); i++)
{
NPC cur_npc = Screen->LoadNPC(i);
if ( cur_npc->Tile < nExcludeTileStart ||
cur_npc->Tile > nExcludeTileEnd )
{
//do your effect here, this NPC is not in the range to exclude.
}
}


Does this make sense?

Nope. The new Enemy Editor would allow for tiles to be all over the place, which isn't good. *sigh* I can't make this script I'm working on unless I can modify the enemy itself. It's not the TILES I need to change. It's the whole entire enemy.

blue_knight
02-16-2007, 04:58 PM
What we really need is some sort of user definable flags field in the NPC. The quest builder could set the flags (as a number) in the enemy editor, then you could read that variable in the script (npc->flags or something) and act on it. But as far as I know no such thing currently exists. While I've had some luck in storing data in unused parts of the structure (such as BossPal for non-bosses), I don't know of anyway of getting the required info into the script or NPC ahead of time.

Perhaps you can look at the NPC's HP and/or Damage and base your decision on that? You don't want your effect to happen to "tough" enemies right?