Announcement

Collapse
No announcement yet.

GetInput

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GetInput

    Still more SLIC questions ...

    Has anyone used GetInput? It's syntax has to be:

    Return GetInput;

    I assume it allows you to get input from the player somehow, although how this is done with a function return is beyond me. Is that correct? I haven't found a single instance of it used in slc code.

  • #2
    This is a new one on me. Where did you find this?

    Comment


    • #3
      GetInput is one of three keyword you can find in Locutus' slic doc and in my Flag list. I classified it as slic function that is probably wrong. It looks rather like something Stop and Continue. Stop is used in slic code the two other keywords aren't used. Possible all the keywords can be used in loops for example. It would be interesting what the use of these words is in other programing languages.

      -Martin
      Civ2 military advisor: "No complaints, Sir!"

      Comment


      • #4
        'Continue' is ok, but you have to use it with 'Return'. There was an example in the Function Reference doc:

        Code:
         int_t i;
                    location_t my_loc;
                    //initialise these variables
               
                    for(i = 0; i < 8; i = i + 1) {
                          GetNeighbor(city[0].location, i, my_loc);
                          if(AllUnitsCanBeExpelled(my_loc)) {
                                //do stuff
                                return CONTINUE;
                          }
                    }
                    //if all of the enemy units 1 tile away from city[0], do stuff, then break the for loop and continue.
        It would be nice if this 'GetInput' returned some mouse value though.

        Comment


        • #5
          That was it I had in mind for continue, but GetInput is still a mystery.

          At least we have a possibility to break loops now.

          Well we could use it like ahenobarb suggested but then it wouldn't make sense that it returns some mouse values. It could be used as return argument for a function to get to know what it does well at least if it is something with an integer representaion:

          [CODE]
          int_f TestFunktion(){
          return GetInput;
          }

          -Martin
          Civ2 military advisor: "No complaints, Sir!"

          Comment


          • #6
            Originally posted by Peter Triggs
            'Continue' is ok, but you have to use it with 'Return'. There was an example in the Function Reference doc:

            Code:
             int_t i;
                        location_t my_loc;
                        //initialise these variables
                   
                        for(i = 0; i < 8; i = i + 1) {
                              GetNeighbor(city[0].location, i, my_loc);
                              if(AllUnitsCanBeExpelled(my_loc)) {
                                    //do stuff
                                    return CONTINUE;
                              }
                        }
                        //if all of the enemy units 1 tile away from city[0], do stuff, then break the for loop and continue.
            It would be nice if this 'GetInput' returned some mouse value though.

            Return CONTINUE is also used in Tut_main.slc

            Code:
            //oh, baby, show me your workaround face
            
            trigger 'TCheckQueue' on "CityWindow.CloseButton" when (1) {
            int_t player;
            player = g.player;
            
            	if(CityBuildingWonder(player)) {
            		EARLY_BUILDING_STARTED = 1;
            		DisableTrigger('TCheckQueue');
            		return CONTINUE;
            	} elseif(CityBuildingBuilding(player)) { 
            		EARLY_BUILDING_STARTED = 1;
            		DisableTrigger('TCheckQueue');
            		return CONTINUE;
            	} elseif (AllCitiesBuilding(player)) {
            		Message(g.player, 'TMKeepExploring');
            		EARLY_BUILDING_STARTED = 1;
            		DisableTrigger('TCheckQueue');
            		return CONTINUE;
            	} else {
            		return CONTINUE;
            	}
            }
            and in a HandleEvent

            Code:
            //count the number of caravans and let the player know if the have any goods
            
            HandleEvent(CreateUnit) 'TCheckForCaravans' post {
            int_t k;
            city_t tmpCity;
            CARAVANS_AVAILABLE = TradePoints(player[0]) - TradePointsInUse(player[0]);
            
            	if(IsHumanPlayer(player[0]) && CARAVANS_AVAILABLE) {
            		for(k = 0; k < player[0].cities; k = k + 1) {
            			GetCityByIndex(player[0], k, tmpCity);
            			if(CityIsValid(tmpCity)) {	
            				if(FindGood(tmpCity.location) >= 0) {	
            					city[0] = tmpCity;	
            					Message(g.player, 'TMYouHaveAGood');
            					DisableTrigger('TCheckForCaravans');
            					return CONTINUE;
            				} else {
            					Message(g.player, 'TMYouHaveNoGoods');
            					DisableTrigger('TCheckForCaravans');
            				}
            			}
            		}
            	}
            }
            It seems that this code would function fine without return CONTINUE and it is not clear in this code where CONTINUE is being returned to.

            I like Martin's idea about using GetInput in a function. Perhaps, the function could prompt the user to enter something either alphanumeric text (a single key entry or multiple keys?) or mouse clicks, which would then be returned to the statement that called the function. It's not really clear how a mouse click could be returned to the statement. What form would the return be? screen coordinates for the spot that was clicked? 1 or 0?

            Comment


            • #7
              Comparing it with Java stuff it looks like continue is used to break a loop cycle in order to continue with the next loop cycle. In all of the examples we see in this thread it wouldn't make any difference if it is there or not. So far I understood it it could replace an if - else statement.

              -Martin
              Civ2 military advisor: "No complaints, Sir!"

              Comment


              • #8
                I thought "return CONTINUE" was just the opposite to "return STOP", and - in an event - probably does exactly the same as just "return", or reaching the final closing brace.

                Comment

                Working...
                X