Period in function definition giving invalid syntax error

Viewed 72

I'm testing procedural generation and I need to use player.x and player.z in the function, but it gives me an invalid syntax error on the periods.

  File "/path/to/file.py", line 17
    def generateheightmap(noise1, noise2, player.x, player.z):
                                                ^
SyntaxError: invalid syntax

My code:

from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
from ursina.shaders import basic_lighting_shader
from perlin_noise import PerlinNoise
from PIL import Image
from random import *

app = Ursina()

noise1 = PerlinNoise(octaves=1, seed=seed())
noise2 = PerlinNoise(octaves=3, seed=seed())

player = FirstPersonController()

print(player.x,player.z)

def generateheightmap(noise1, noise2, player.x, player.z):
    for x in range(100):
        for z in range(100):
            x = x - 50 + player.x
            z = z - 50 + player.z
            noise1calc = noise1([x/10,z/10])
            noise2calc = noise2([x/10,x/10])
            y = noise1calc * noise2calc
            
def update():
    generateheightmap(noise1, noise2)

app.run()
1 Answers

player.x and player.z are invalid identifiers for function parameters.

Accept player from the caller instead.

player = FirstPersonController()

print(player.x,player.z)

# def generateheightmap(noise1, noise2, player.x, player.z):  # Replace this
def generateheightmap(noise1, noise2, player):                # with this
    for x in range(100):
        for z in range(100):
            x = x - 50 + player.x
            z = z - 50 + player.z
            noise1calc = noise1([x/10,z/10])
            noise2calc = noise2([x/10,x/10])
            y = noise1calc * noise2calc
            
def update():
    # generateheightmap(noise1, noise2)        # Replace this
    generateheightmap(noise1, noise2, player)  # with this
Related