# Löschen aller Gebäude

Im folgenden betrachten wir eine Funktion die alle Gebäude einer Partei zerstört.

```lua
function deleteallbuildings(partei)
	counter = 1
	x = 0
	while counter < 83 do		
		x = Buildings.Amount(partei,counter, Buildings.READY)
 
		while x~=0 do		
			Buildings.Delete(Buildings.GetFirstBuilding(partei,counter),partei)
			x = x-1
		end
		counter = counter +1		
	end
end
```

Die Funktion erwartet als Parameter die entsprechende Partei und kann so aufgerufen werden

`deleteallbuildings(2)`&#x20;

Falls man möchte dass alle Gebäude zerstört werden sollen außer Gründungsgebäude kann man die Funktion entsprechend anpassen:

```lua
function deleteallbuildings(partei)
	counter = 1
	x = 0
	while counter < 83 do
		if counter == 46 then
			counter=49
		end
		x = Buildings.Amount(partei,counter, Buildings.READY)
		while x~=0 do		
			Buildings.Delete(Buildings.GetFirstBuilding(partei,counter),partei)
			x = x-1
		end
		counter = counter +1		
	end
end
```

**Erklärung**: Alle Gebäude haben eine Nummer von 1 bis 83, man läuft über alle Gebäudeeinträge und löscht die entsprechende Anzahl der jeweiligen Gebäude. Die Gründungsgebäude, Kleiner Turm , Großer Turm und Burg haben die Nummern 46,47 und 48 weshalb wir diese im unteren Beispiel überspringen.<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.settlers-united.com/s4-lua-api-de/tutorials/advanced-tipps/delete-all-buildings.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
