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 / [SOLVED] Variable copying

Author
Message
marvin944
10
Years of Service
User Offline
Joined: 27th Aug 2013
Location:
Posted: 17th Nov 2019 21:52
Is it possible to copy a varibale defined by a type into another variable with the same type by just doing this:

type test
a as integer
b as integer
endtype

dim orig[10] as test
dim copy[10] as test

copy[1]=orig[1]
Dutch

The author of this post has marked a post as an answer.

Go to answer

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 17th Nov 2019 22:06
no you need to
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
marvin944
10
Years of Service
User Offline
Joined: 27th Aug 2013
Location:
Posted: 17th Nov 2019 22:58
Yes, that's what I figured. Very nasty when a type as over 50 variables...
Dutch
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 17th Nov 2019 23:46
I think your original syntax, "copy[1]=orig[1]", will work.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 18th Nov 2019 01:20
Quote: "I think your original syntax, "copy[1]=orig[1]", will work."


Pretty sure it does also, but i don't recall if it is a shallow or deep copy

It also resulted in a massive memory leak in dbpro when the type contained strings, not sure if that is an issue in agk or not
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 18th Nov 2019 02:04 Edited at: 18th Nov 2019 02:07
This post has been marked by the post author as the answer.
It will make a copy of orig[1] and assign that to copy[1]
So if you change orig[1] afterwards it wont change copy[1]

As an aside i found out the other day, if you want to assign different types with common values you can use json like so;



I thought it would be super handy if the scene editor used typed arrays. That way you could easily populate your own arrays with the values from the scene editor arrays
marvin944
10
Years of Service
User Offline
Joined: 27th Aug 2013
Location:
Posted: 18th Nov 2019 09:46
Not sure why it didn't work the first time, but it does now. Great tips here too, thanks!
Dutch

Login to post a reply

Server time is: 2024-03-28 13:31:55
Your offset time is: 2024-03-28 13:31:55