User Tag List

Results 1 to 5 of 5

Thread: Functions that return pointers

  1. #1
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,304
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.82%

    Functions that return pointers

    Code:
    lweapon ofType(int ID){
    	lweapon Type;
    	for(int i=1;i<=Screen->NumLWeapons();i++){
    		Type = Screen->LoadLWeapon(i);
    		if(Type->ID == ID) return Type;
    	}
    	lweapon Null; return Null;
    }
    I was really quite surprised we could do this.
    Does anyone have a better idea for 'none on screen' than returning one that doesn't point anywhere though?

  2. #2
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,143
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.68%

    Re: Functions that return pointers

    That's the cleanest way to do it. Besides, we always check "whatever->isValid()" before using it, right?

    Right?

    ... right...?

    -_-'''
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  3. #3
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,304
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.82%

    Re: Functions that return pointers

    Well, no.

    If I was using that code I might do though.
    Not that I probably will use that code, I was just surprised that it worked more than anything.

    Could be useful for someone else?

  4. #4
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,143
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.68%

    Re: Functions that return pointers

    It's not a useless snippet. It returns the first lweapon of that kind. But, the convenience comes at a cost: 1. You don't get access to any other lweapons (maybe not a problem), and 2. You have to check to make sure the pointer is valid before you use it (again, maybe not a problem).

    However, certainly, it's generally more useful to iterate over all weapons of a given type.
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  5. #5
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,304
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.82%

    Re: Functions that return pointers

    Well no, I didn't post it because I thought it was useless.

    It wouldn't be hard to modify with NumLWeaponsOfType() and another parameter to let it know which of the lweapons of that type you wanted to return.

    I only have one loop checking through LWeapons in my global script though anyway, checking through all lweapons on-screen multiple times per frame doesn't seem like a good idea.

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