Coder Social home page Coder Social logo

Foreach overflow? about ysi-includes HOT 7 CLOSED

PatchwerkQWER avatar PatchwerkQWER commented on June 11, 2024
Foreach overflow?

from ysi-includes.

Comments (7)

Crayder avatar Crayder commented on June 11, 2024

Try: if(id == -1)

-1 means the iterator is full. Technically the end of the iterator doesn't mean it is full, but I see what you were trying to do.

from ysi-includes.

PatchwerkQWER avatar PatchwerkQWER commented on June 11, 2024

I know. I always use if(id == -1). You can see first code. Here is solution with id == -1but it doesn't work. I don't know why.

from ysi-includes.

Crayder avatar Crayder commented on June 11, 2024

Try:

stock SellPlayerVehicle(playerid, modelid){
    new id = Iter_Free(PlayerVehicle[playerid]);
    if(Iter_Add(PlayerVehicle[playerid], id) == -1) return -1;
    MsgF(playerid, -1, "SellPlayerVehicle - %d", id);

Also, study up on multi-iterators. You shouldn't be using an iterator array for this vehicle ownership thing. Multiple players can't own the same vehicle (I'm guessing, if they can your script is weird), so a multi-iterator would be easiest to handle.

from ysi-includes.

Y-Less avatar Y-Less commented on June 11, 2024

Iter_Add and Iter_Free return cellmin on failure:

https://github.com/Misiur/YSI-Includes/blob/8bdf76d5a17366e2813b4ec7623913fc4c6590ac/YSI_Data/y_foreach/impl.inc#L960

The reason is that -1 is now considered a valid value for some iterators. In fact cellmin could be, but is less likely to be. I like cellmin because it has no opposite value - it is NOT -cellmax (that is cellmin + 1. In fact, it is more like -0, so I use it for invalid values.

This iterator will happily return -1 as a valid value:

https://github.com/Misiur/YSI-Includes/blob/8bdf76d5a17366e2813b4ec7623913fc4c6590ac/YSI_Data/y_foreach/iterators.inc#L252-L259

from ysi-includes.

Crayder avatar Crayder commented on June 11, 2024

What? Maybe that's why I was facing so many bugs not long ago. I've been using -1.

How should a -1 situation be dealt with if it is somehow valid? Like, my script only requires indexes 0-99. Should I be checking for cellmin too?

@PatchwerkQWER: The correct code would be:

stock SellPlayerVehicle(playerid, modelid){
    new id = Iter_Free(PlayerVehicle[playerid]);
    if(Iter_Add(PlayerVehicle[playerid], id) == cellmin) return -2;
    MsgF(playerid, -1, "SellPlayerVehicle - %d", id);

from ysi-includes.

Y-Less avatar Y-Less commented on June 11, 2024

Just because your script only needs 0-99 doesn't mean they all do. -1 is in theory valid in some iterators - even if you don't personally use it y_iterate still has to handle it, and does.

from ysi-includes.

PatchwerkQWER avatar PatchwerkQWER commented on June 11, 2024

@Crayder You don't know how work my Vehicle System. It doesn't depend on vehicle id. So I doesn't need new multi iterator.

@Y-Less Okay, now it works.So, Can I use everywhere cellmin istead of -1? (If I get it)

from ysi-includes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.