Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Problem with StartFunction.agc:5: error: "player1" has not been defined as a type

Author
Message
SirRolo
8
Years of Service
User Offline
Joined: 24th Mar 2016
Location:
Posted: 27th Dec 2017 07:24
I keep getting this error, not sure why. I am new to Types but I am trying to use this function to enter a name but I don't know how to define it before I send it down to the function to define it. I thought I did define that Player1 was a type because it works with 3 other of my other function.

This is my Types

Type Players
PlayerName$
PlayerNum
PlayerRace$
PlayerLvl
Planet as Planets[200]
Endtype

Type Planets
Size
EcoLvl
MineralLvl
PlayerOwner
Que as Integer[4]
EndType


This is the first thing my Program reads:

Player1 as Players

So I figure The Variable Player1 is defined as a type



this is the call for a function doName(Player1.PlayerName$)

DoName(Player1.PlayerName$)

And all I keep getting is the above error error.
adambiser
AGK Developer
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 27th Dec 2017 07:52
How does the first line of your DoName function look?
What is line 5 of StartFunction.agc?
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 27th Dec 2017 11:25 Edited at: 27th Dec 2017 11:29
Try

//calling
DoName(Player1)

//passing by value
Function DoName(Player1 as Players)

//passing by ref
Function DoName(Player1 ref as Players)

//if you want to pass only the playername attribute:
DoName(Player1.PlayerName$)

Function DoName(PlayerName$ as string)

//you can also initialize the type usage inside the function which is useful if you want to use it only locally
Function DoName()
Player1 as Players
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 27th Dec 2017 14:52
Id also define the "Planets" type BEFORE the "Player" Type as Planets is used inside of the player type and so should already be defined first.

Make sure that your types ae defeined before the function that uses them (Ie BEFORE DoName)

From the AGK2 Documentation
Quote: " 1. To reduce iterations, the compiler will process TYPE declarations and FUNCTION declarations in the same sweep, so if you place the TYPE ENDTYPE command after the function, the function will not be able to compile as it will not know what the TYPE is. Make sure you declare all your types before declaring any functions that use them."

Login to post a reply

Server time is: 2024-11-24 04:37:52
Your offset time is: 2024-11-24 04:37:52