Stuck Adding Items to My PureBasic Adventure Game

Just starting out? Need help? Post your questions and find answers here.
samantha
New User
New User
Posts: 1
Joined: Thu Apr 25, 2024 2:37 am

Stuck Adding Items to My PureBasic Adventure Game

Post by samantha »

Hi all,
I'm trying to create a simple text-based adventure game in PureBasic. The player should be able to explore different locations and interact with objects by typing commands. I've written the core logic for moving around and implemented basic descriptions for the locations. However, I'm facing an issue when trying to add items to the game.

Code: Select all

' Define a structure to store location data
Structure LocationData
  name$ As String
  description$ As String
  items As List  ' This line is causing the issue
EndStructure

' Define locations
Dim locations(2) As LocationData

locations[0].name$ = "Forest"
locations[0].description$ = "You are standing in a dense forest."

' Trying to add an item to the Forest location (index 0)
locations[0].items.Add( "Sword" )  ' Error might occur here

' Game loop (simplified)
Do
  ' ... (display location description)
  ' ... (get player input)
  ' ... (process player commands)
Loop
When I try to run the code, I get an error message around the line `locations[0].items.Add( "Sword" )`. It seems the `List` data type isn't recognized or there's an issue with how I'm trying to add elements to it.

Can you help me understand why I'm getting this error and how to fix it? Is there a specific way to define and use lists in PureBasic to store items within locations?
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Stuck Adding Items to My PureBasic Adventure Game

Post by infratec »

Write PB code, then PB will understand. :wink:
User avatar
Bisonte
Addict
Addict
Posts: 1320
Joined: Tue Oct 09, 2007 2:15 am

Re: Stuck Adding Items to My PureBasic Adventure Game

Post by Bisonte »

infratec wrote: Thu Apr 25, 2024 7:04 am Write PB code, then PB will understand. :wink:
My thoughts ;)
But I think its a bot....
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
Post Reply