User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15

Thread: Command/Variable Questions

  1. #1
    Ultimate Prankster Lucario QDB Manager
    Just registered
    Nimono's Avatar
    Join Date
    Nov 2005
    Location
    Static Void Kingdom
    Age
    32
    Posts
    1,963
    Mentioned
    5 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    6,276
    Level
    24
    vBActivity - Bars
    Lv. Percent
    43.96%

    Command/Variable Questions

    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.

  2. #2
    Octorok
    Join Date
    Oct 2006
    Age
    47
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    969
    Level
    10
    vBActivity - Bars
    Lv. Percent
    78.93%

    Re: Command/Variable Questions

    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)?

  3. #3
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,028
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.53%

    Re: Command/Variable Questions

    Rand(x) returns some integer y such that 0 <= y < x.
    When in doubt, don't forget to check the documentation.

  4. #4
    Ultimate Prankster Lucario QDB Manager
    Just registered
    Nimono's Avatar
    Join Date
    Nov 2005
    Location
    Static Void Kingdom
    Age
    32
    Posts
    1,963
    Mentioned
    5 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    6,276
    Level
    24
    vBActivity - Bars
    Lv. Percent
    43.96%

    Re: Command/Variable Questions

    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?

  5. #5
    Keese
    ZC Developer

    Join Date
    Jan 2007
    Age
    34
    Posts
    52
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    vBActivity - Stats
    Points
    781
    Level
    9
    vBActivity - Bars
    Lv. Percent
    80.81%

    Re: Command/Variable Questions

    Quote Originally Posted by pikaguy900 View Post
    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.

  6. #6
    Ultimate Prankster Lucario QDB Manager
    Just registered
    Nimono's Avatar
    Join Date
    Nov 2005
    Location
    Static Void Kingdom
    Age
    32
    Posts
    1,963
    Mentioned
    5 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    6,276
    Level
    24
    vBActivity - Bars
    Lv. Percent
    43.96%

    Re: Command/Variable Questions

    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.

  7. #7
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,028
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.53%

    Re: Command/Variable Questions

    Quote Originally Posted by pikaguy900 View Post
    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:
    Code:
    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
    Code:
    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
    Code:
    int whatever = 1 + Rand(10);
    would get you a number from 1 to 10, inclusive.

  8. #8
    Ultimate Prankster Lucario QDB Manager
    Just registered
    Nimono's Avatar
    Join Date
    Nov 2005
    Location
    Static Void Kingdom
    Age
    32
    Posts
    1,963
    Mentioned
    5 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    6,276
    Level
    24
    vBActivity - Bars
    Lv. Percent
    43.96%

    Re: Command/Variable Questions

    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?

  9. #9
    Octorok
    Join Date
    Oct 2006
    Age
    47
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    969
    Level
    10
    vBActivity - Bars
    Lv. Percent
    78.93%

    Re: Command/Variable Questions

    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"

  10. #10
    Ultimate Prankster Lucario QDB Manager
    Just registered
    Nimono's Avatar
    Join Date
    Nov 2005
    Location
    Static Void Kingdom
    Age
    32
    Posts
    1,963
    Mentioned
    5 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    6,276
    Level
    24
    vBActivity - Bars
    Lv. Percent
    43.96%

    Re: Command/Variable Questions

    Quote Originally Posted by blue_knight View Post
    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. :)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social