September 25, 2020, 02:31:51 AM

Author Topic: is there any way in blitzmax to assign an array name to a variable?  (Read 234 times)

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 52
Consider this piece of code. I want to use a string variable to represent an array name.

Code: [Select]
Strict

Local A[]=[1]
Local B[]=[2]
Local ans$="A"

Print ans$[0]
ans$="B"
Print ans$[0]

This code obviously doesn't work properly (interestingly it prints the ASCII codes of A & B). I can't remember what this behaviour is called (substitution?) but can it be done in blitzmax? If so it would be very useful. I'd be grateful for any pointers thanks.

Offline GW

  • Full Member
  • ***
  • Posts: 202
Re: is there any way in blitzmax to assign an array name to a variable?
« Reply #1 on: June 17, 2020, 06:22:31 AM »
that doesn't make a lot of sense.   
You can try looking at the 'StringMap' type to store and array with a string handle.  You also might be able to do something similar with reflection.


Offline Juiceter

  • Jr. Member
  • **
  • Posts: 52
Re: is there any way in blitzmax to assign an array name to a variable?
« Reply #2 on: June 17, 2020, 07:09:21 AM »
I can always pass an array as a parameter to a function anyway, so it's not much of a problem for what I'm doing.
It just seemed like a logical and easy way to substitute a string for an array name. It just struck me as interesting.

Offline _PJ_

  • Jr. Member
  • **
  • Posts: 92
Re: is there any way in blitzmax to assign an array name to a variable?
« Reply #3 on: June 17, 2020, 07:25:58 AM »
_removed

Offline Derron

  • Hero Member
  • *****
  • Posts: 3178
Re: is there any way in blitzmax to assign an array name to a variable?
« Reply #4 on: June 17, 2020, 09:59:55 AM »
If that was "logical" to do so, then this would work too:


local myVariable:Int = 10
print ("myVariable" - 5)

and no, it doesn't.

You could of course do as GW suggesteD: TMap or TStringMap allow a "string" key and an array as value (key=>value container).


bye
Ron

Offline TomToad

  • Hero Member
  • *****
  • Posts: 513
Re: is there any way in blitzmax to assign an array name to a variable?
« Reply #5 on: June 17, 2020, 02:31:32 PM »
You can assign an array to another variable if you want.
Code: [Select]
Strict

Local A[]=[1]
Local B[]=[2]
Local ans[]=A

Print ans[0]
ans=B
Print ans[0]
------------------------------------------------
8 rabbits equals 1 rabbyte.

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal