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.

AppGameKit Classic Chat / problem with assigning strings to an array and displaying them

Author
Message
Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 26th Nov 2013 09:42 Edited at: 26th Nov 2013 09:59
Hi all,

While commuting to work this morning, I tried to get the program I listed below working. It should assign ten strings to an array and then display them in a descending row. For some reason, only the last line shows. I'm not really sure what I am doing wrong, but I guess it might be something quite simple. Lack of sleep from taking care of a little baby isn't helping me much perception-wise Can someone offer assistance? It would be appreciated!

=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 26th Nov 2013 11:14 Edited at: 26th Nov 2013 11:15
The problem is this line...



You are creating text ID 0 over and over again, changing it to the following...



fixes your problem

Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 26th Nov 2013 11:26 Edited at: 26th Nov 2013 11:46
Edit: I knew someone else would chime in with the answer as I waffled on!

At a glance all your Text[id].id values will be 0 as you've never initialised them. You're running GetTextExists and CreateText with an ID of 0 all the time.

I would try swapping your line:
if GetTextExists(Text[Id].Id) = 0
for
if Text[Id].Id = 0
To check if the variable hasn't been initialised, and if not, let AppGameKit initialise it for you. So swap:
CreateText(Text[Id].Id, Text[Id].Text$)
With
Text[Id].Id = CreateText(Text[Id].Text$)

So your function looks like ...


I found the use of text[id].id quite confusing, as ID means very little and it may trip you up in the future and cause some head scratching. Typically what I do is name my variables in such a way that I know what type of object they're referring to, which saves me head scratching. So in this case I would personally use some prefixes like this:



This way whenever you see txtID the txt prefix alerts you to the fact this should always point to an AppGameKit text object ID.

I also use:
snd (sound ID)
obj (3d object)
img (image file)
tex (image file I'm using as a 3D texture)
spr (sprite)
etc.

Then I can have types such as (how I define a type)



This is just how I like to do it. At a glance I can look at any variable like this ...

typArrWarrior[5].sprHealthBar

I know instantly this is a user defined type, and array, and I'm referencing an AppGameKit sprite ID. Overkill for some, but really useful for me to keep things organised. Sorry if this seems off topic but the whole text[id].id thing personally makes it harder for me to read the code.

Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 26th Nov 2013 14:44
Thank you ever so much both =PRoF= and Fallout! I'd been staring and staring at the code, not seeing were I went wrong. I'll certainly consider using the naming-conventions Fallout mentions, since they will add a lot to the readability of code. Thank you for elaborating on that.

Login to post a reply

Server time is: 2024-05-20 13:19:27
Your offset time is: 2024-05-20 13:19:27